aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/qpdf/QPDF_Name.hh
blob: b5d3c318d21f66bf24da9ff2c5992f8a0875f6a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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;
    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