11 #ifndef __UT_JSONPath__
12 #define __UT_JSONPath__
89 template <
typename T,
class FUNC>
99 traverse(matches, &src, &src, expr);
101 return matches.size() > 0;
105 static inline void traverseArray(
const T &item,
110 for (
auto it = FUNC::arrayBegin(item),
n = FUNC::arrayEnd(item);
112 traverse(matches, root, *it, expr);
114 static inline void traverseMap(
const T &item,
119 for (
auto it = FUNC::mapBegin(item),
n = FUNC::mapEnd(item);
121 traverse(matches, root, it->second, expr);
139 if (!FUNC::isArray(src) && !FUNC::isMap(src))
154 if (FUNC::isArray(src))
155 traverseArray(*src, matches, root, expr);
157 traverseMap(*src, matches, root, expr);
160 traverse(matches, root, src, expr+2);
175 else if (*expr ==
'.')
190 if (FUNC::isArray(src))
191 traverseArray(*src, matches, root, expr);
193 traverseMap(*src, matches, root, expr);
195 else if (FUNC::isArray(src))
198 const char *
end = part.
end();
202 const T *kid = FUNC::arrayItem(src, idx);
204 traverse(matches, root, kid, expr);
211 const T *kid = FUNC::mapItem(src, str.
buffer());
213 traverse(matches, root, kid, expr);
237 return arr && idx >= 0 && idx < arr->
size() ? arr->
get(idx) :
nullptr;
244 return map ? map->
get(name) :
nullptr;
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
SYS_NO_DISCARD_RESULT UT_JSONValueArray * getArray() const
Get the array value (may return a NULL pointer)
UT_API const char * UTjsonExtractPath(UT_StringView &path, const char *x)
SYS_NO_DISCARD_RESULT const UT_JSONValue * get(int64 i) const
Access a const entry by index.
static bool isArray(const UT_JSONValue *obj)
UT_JSONValueArray stores a list of UT_JSONValue objects.
GLsizei const GLchar *const * path
SYS_FORCE_INLINE const char * buffer() const
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator end() const
Returns a constant iterator pointing to the end of the string.
static bool isMap(const UT_JSONValue *obj)
const_iterator end() const
Class to implement UT_JSONPath_T parsing for a UT_JSONValue.
A utility class to do read-only operations on a subset of an existing string.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE exint length() const
Returns the length of the string in bytes.
const_iterator begin() const
UT_JSONValueArray::const_iterator array_iterator
SYS_API SYS_ParseStatus SYSparseInteger(const char *begin, const char *&end, int8 &number, int base=0, SYS_ParseFlags flags=SYS_ParseFlags::None)
SYS_NO_DISCARD_RESULT UT_JSONValueMap * getMap() const
Get the map value (may return a NULL pointer)
GLuint const GLchar * name
Implement simple JSONPath parser.
static map_iterator mapEnd(const UT_JSONValue &obj)
static const UT_JSONValue * mapItem(const UT_JSONValue *obj, const char *name)
UT_API bool UTjsonSplitComma(UT_StringView &part, UT_StringView &path)
static bool find(UT_Set< const T * > &matches, const T &src, const char *expr)
SYS_FORCE_INLINE bool UTisstring(const char *s)
SYS_FORCE_INLINE void append(char character)
A number was successfully parsed.
SYS_NO_DISCARD_RESULT Type getType() const
Get the type of data stored in the object.
Class to store JSON objects as C++ objects.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator begin() const
Returns a constant iterator pointing to the beginning of the string.
static const UT_JSONValue * arrayItem(const UT_JSONValue *obj, exint idx)
UT_Array< UT_JSONValue * >::const_iterator const_iterator
static array_iterator arrayBegin(const UT_JSONValue &obj)
static array_iterator arrayEnd(const UT_JSONValue &obj)
static map_iterator mapBegin(const UT_JSONValue &obj)
SYS_FORCE_INLINE const UT_JSONValue * get(int64 i) const
Access a const entry by index.
const iterator const_iterator
SYS_FORCE_INLINE int64 size() const
Return size of the array.