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()
87 return m_aState.back();
89 void SkipSpace(
const char *&pStr,
size_t &nLength);
90 void AdvanceChar(
const char *&pStr,
size_t &nLength);
91 bool EmitUnexpectedChar(
char ch,
const char *pszExpecting =
nullptr);
92 bool StartNewToken(
const char *&pStr,
size_t &nLength);
93 bool CheckAndEmitTrueFalseOrNull(
char ch);
94 bool CheckStackEmpty();
98 bool EmitException(
const char *pszMessage);
101 CPLJSonStreamingParser();
102 virtual ~CPLJSonStreamingParser();
104 void SetMaxDepth(
size_t nVal);
105 void SetMaxStringSize(
size_t nVal);
106 bool ExceptionOccurred()
const
108 return m_bExceptionOccurred;
111 static std::string GetSerializedString(
const char *pszStr);
113 virtual void Reset();
114 virtual bool Parse(
const char *pStr,
size_t nLength,
bool bFinished);
116 virtual void String(
const char * ,
size_t )
119 virtual void Number(
const char * ,
size_t )
122 virtual void Boolean(
bool )
129 virtual void StartObject()
132 virtual void EndObject()
135 virtual void StartObjectMember(
const char * ,
size_t )
139 virtual void StartArray()
142 virtual void EndArray()
145 virtual void StartArrayMember()
149 virtual void Exception(
const char * )
154 #endif // __cplusplus
158 #endif // CPL_JSON_STREAMIN_PARSER_H