2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-29 16:30:53 +00:00
qpdf/libqpdf/qpdf/QPDF_Name.hh
m-holger 431987475b Add new method QPDF_Name::analyzeJSONEncoding
Provide a custom method to check whether a name is valid utf8. Integrate
checking for characters that need to be escaped in JSON.
2024-02-16 10:52:44 +00:00

35 lines
1.1 KiB
C++

#ifndef QPDF_NAME_HH
#define QPDF_NAME_HH
#include <qpdf/QPDFValue.hh>
class QPDF_Name: public QPDFValue
{
public:
~QPDF_Name() override = default;
static std::shared_ptr<QPDFObject> create(std::string const& name);
std::shared_ptr<QPDFObject> copy(bool shallow = false) override;
std::string unparse() override;
JSON getJSON(int json_version) override;
void writeJSON(int json_version, JSON::Writer& p) override;
// Put # into strings with characters unsuitable for name token
static std::string normalizeName(std::string const& name);
// Check whether name is valid utf-8 and whether it contains characters that require escaping.
// Return {false, false} if the name is not valid utf-8, otherwise return {true, true} if no
// characters require or {true, false} if escaping is required.
static std::pair<bool, bool> analyzeJSONEncoding(std::string const& name);
std::string
getStringValue() const override
{
return name;
}
private:
QPDF_Name(std::string const& name);
std::string name;
};
#endif // QPDF_NAME_HH