29 #ifndef CPL_JSON_STREAMIN_PARSER_H
30 #define CPL_JSON_STREAMIN_PARSER_H
34 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
40 class CPL_DLL CPLJSonStreamingParser
56 bool m_bExceptionOccurred =
false;
57 bool m_bElementFound =
false;
59 int m_nLineCounter = 1;
60 int m_nCharCounter = 1;
61 std::vector<State> m_aState{};
62 std::string m_osToken{};
69 std::vector<ArrayState> m_abArrayState{};
70 bool m_bInStringEscape =
false;
71 bool m_bInUnicode =
false;
72 std::string m_osUnicodeHex{};
73 size_t m_nMaxDepth = 1024;
74 size_t m_nMaxStringSize = 10000000;
83 std::vector<MemberState> m_aeObjectState{};
85 enum State currentState() {
return m_aState.back(); }
86 void SkipSpace(
const char*& pStr,
size_t& nLength);
87 void AdvanceChar(
const char*& pStr,
size_t& nLength);
88 bool EmitUnexpectedChar(
char ch,
const char* pszExpecting =
nullptr);
89 bool StartNewToken(
const char*& pStr,
size_t& nLength);
90 bool CheckAndEmitTrueFalseOrNull(
char ch);
91 bool CheckStackEmpty();
95 bool EmitException(
const char* pszMessage);
98 CPLJSonStreamingParser();
99 virtual ~CPLJSonStreamingParser();
101 void SetMaxDepth(
size_t nVal);
102 void SetMaxStringSize(
size_t nVal);
103 bool ExceptionOccurred()
const {
return m_bExceptionOccurred; }
105 static std::string GetSerializedString(
const char* pszStr);
107 virtual void Reset();
108 virtual bool Parse(
const char* pStr,
size_t nLength,
bool bFinished);
110 virtual void String(
const char* ,
size_t ) {}
111 virtual void Number(
const char* ,
size_t ) {}
112 virtual void Boolean(
bool ) {}
113 virtual void Null() {}
115 virtual void StartObject() {}
116 virtual void EndObject() {}
117 virtual void StartObjectMember(
const char* ,
size_t ) {}
119 virtual void StartArray() {}
120 virtual void EndArray() {}
121 virtual void StartArrayMember() {}
123 virtual void Exception(
const char* ) {}
126 #endif // __cplusplus
130 #endif // CPL_JSON_STREAMIN_PARSER_H