diff -r 7b3a3130be44 -r 64ded9f6a6c6 ucx/cx/json.h --- a/ucx/cx/json.h Mon Jan 06 22:22:55 2025 +0100 +++ b/ucx/cx/json.h Tue Feb 25 21:11:00 2025 +0100 @@ -309,7 +309,7 @@ */ CxJsonTokenType tokentype; /** - * True, iff the @c content must be passed to cx_strfree(). + * True, if the @c content must be passed to cx_strfree(). */ bool allocated; /** @@ -374,11 +374,6 @@ * Internally reserved memory for the value buffer stack. */ CxJsonValue* vbuf_internal[8]; - - /** - * Used internally. - */ - bool tokenizer_escape; // TODO: check if it can be replaced with look-behind }; /** @@ -449,6 +444,8 @@ bool sort_members; /** * The maximum number of fractional digits in a number value. + * The default value is 6 and values larger than 15 are reduced to 15. + * Note, that the actual number of digits may be lower, depending on the concrete number. */ uint8_t frac_max_digits; /** @@ -461,6 +458,10 @@ * Indentation is only used in pretty output. */ uint8_t indent; + /** + * Set true to enable escaping of the slash character (solidus). + */ + bool escape_slash; }; /** @@ -474,6 +475,7 @@ * @return new JSON writer settings */ cx_attr_nodiscard +cx_attr_export CxJsonWriter cxJsonWriterCompact(void); /** @@ -483,13 +485,13 @@ * @return new JSON writer settings */ cx_attr_nodiscard +cx_attr_export CxJsonWriter cxJsonWriterPretty(bool use_spaces); /** * Writes a JSON value to a buffer or stream. * - * This function blocks until all data is written or an error when trying - * to write data occurs. + * This function blocks until either all data is written, or an error occurs. * The write operation is not atomic in the sense that it might happen * that the data is only partially written when an error occurs with no * way to indicate how much data was written. @@ -506,6 +508,7 @@ * @retval non-zero when no or not all data could be written */ cx_attr_nonnull_arg(1, 2, 3) +cx_attr_export int cxJsonWrite( void* target, const CxJsonValue* value, @@ -521,6 +524,7 @@ * @see cxJsonDestroy() */ cx_attr_nonnull_arg(1) +cx_attr_export void cxJsonInit(CxJson *json, const CxAllocator *allocator); /** @@ -530,6 +534,7 @@ * @see cxJsonInit() */ cx_attr_nonnull +cx_attr_export void cxJsonDestroy(CxJson *json); /** @@ -567,6 +572,7 @@ */ cx_attr_nonnull cx_attr_access_r(2, 3) +cx_attr_export int cxJsonFilln(CxJson *json, const char *buf, size_t len); #ifdef __cplusplus @@ -667,6 +673,7 @@ * @see cxJsonArrAddValues() */ cx_attr_nodiscard +cx_attr_export CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator); /** @@ -678,6 +685,7 @@ * @see cxJsonArrAddValues() */ cx_attr_nodiscard +cx_attr_export CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator); /** @@ -690,6 +698,7 @@ * @see cxJsonArrAddNumbers() */ cx_attr_nodiscard +cx_attr_export CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num); /** @@ -702,6 +711,7 @@ * @see cxJsonArrAddIntegers() */ cx_attr_nodiscard +cx_attr_export CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num); /** @@ -717,6 +727,7 @@ cx_attr_nodiscard cx_attr_nonnull_arg(2) cx_attr_cstr_arg(2) +cx_attr_export CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char *str); /** @@ -730,6 +741,7 @@ * @see cxJsonArrAddCxStrings() */ cx_attr_nodiscard +cx_attr_export CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str); /** @@ -742,6 +754,7 @@ * @see cxJsonArrAddLiterals() */ cx_attr_nodiscard +cx_attr_export CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit); /** @@ -755,6 +768,7 @@ */ cx_attr_nonnull cx_attr_access_r(2, 3) +cx_attr_export int cxJsonArrAddNumbers(CxJsonValue* arr, const double* num, size_t count); /** @@ -768,6 +782,7 @@ */ cx_attr_nonnull cx_attr_access_r(2, 3) +cx_attr_export int cxJsonArrAddIntegers(CxJsonValue* arr, const int64_t* num, size_t count); /** @@ -784,6 +799,7 @@ */ cx_attr_nonnull cx_attr_access_r(2, 3) +cx_attr_export int cxJsonArrAddStrings(CxJsonValue* arr, const char* const* str, size_t count); /** @@ -800,6 +816,7 @@ */ cx_attr_nonnull cx_attr_access_r(2, 3) +cx_attr_export int cxJsonArrAddCxStrings(CxJsonValue* arr, const cxstring* str, size_t count); /** @@ -813,6 +830,7 @@ */ cx_attr_nonnull cx_attr_access_r(2, 3) +cx_attr_export int cxJsonArrAddLiterals(CxJsonValue* arr, const CxJsonLiteral* lit, size_t count); /** @@ -829,6 +847,7 @@ */ cx_attr_nonnull cx_attr_access_r(2, 3) +cx_attr_export int cxJsonArrAddValues(CxJsonValue* arr, CxJsonValue* const* val, size_t count); /** @@ -846,6 +865,7 @@ * @retval non-zero allocation failure */ cx_attr_nonnull +cx_attr_export int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child); /** @@ -858,6 +878,7 @@ * @see cxJsonCreateObj() */ cx_attr_nonnull +cx_attr_export CxJsonValue* cxJsonObjPutObj(CxJsonValue* obj, cxstring name); /** @@ -870,6 +891,7 @@ * @see cxJsonCreateArr() */ cx_attr_nonnull +cx_attr_export CxJsonValue* cxJsonObjPutArr(CxJsonValue* obj, cxstring name); /** @@ -883,6 +905,7 @@ * @see cxJsonCreateNumber() */ cx_attr_nonnull +cx_attr_export CxJsonValue* cxJsonObjPutNumber(CxJsonValue* obj, cxstring name, double num); /** @@ -896,6 +919,7 @@ * @see cxJsonCreateInteger() */ cx_attr_nonnull +cx_attr_export CxJsonValue* cxJsonObjPutInteger(CxJsonValue* obj, cxstring name, int64_t num); /** @@ -912,6 +936,7 @@ */ cx_attr_nonnull cx_attr_cstr_arg(3) +cx_attr_export CxJsonValue* cxJsonObjPutString(CxJsonValue* obj, cxstring name, const char* str); /** @@ -927,6 +952,7 @@ * @see cxJsonCreateCxString() */ cx_attr_nonnull +cx_attr_export CxJsonValue* cxJsonObjPutCxString(CxJsonValue* obj, cxstring name, cxstring str); /** @@ -940,6 +966,7 @@ * @see cxJsonCreateLiteral() */ cx_attr_nonnull +cx_attr_export CxJsonValue* cxJsonObjPutLiteral(CxJsonValue* obj, cxstring name, CxJsonLiteral lit); /** @@ -953,6 +980,7 @@ * * @param value the value */ +cx_attr_export void cxJsonValueFree(CxJsonValue *value); /** @@ -979,6 +1007,7 @@ */ cx_attr_nonnull cx_attr_access_w(2) +cx_attr_export CxJsonStatus cxJsonNext(CxJson *json, CxJsonValue **value); /** @@ -1251,6 +1280,7 @@ */ cx_attr_nonnull cx_attr_returns_nonnull +cx_attr_export CxJsonValue *cxJsonArrGet(const CxJsonValue *value, size_t index); /** @@ -1266,6 +1296,7 @@ */ cx_attr_nonnull cx_attr_nodiscard +cx_attr_export CxIterator cxJsonArrIter(const CxJsonValue *value); /** @@ -1282,6 +1313,7 @@ */ cx_attr_nonnull cx_attr_nodiscard +cx_attr_export CxIterator cxJsonObjIter(const CxJsonValue *value); /** @@ -1289,20 +1321,21 @@ */ cx_attr_nonnull cx_attr_returns_nonnull +cx_attr_export CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name); #ifdef __cplusplus } // extern "C" -CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) { +static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) { return cx_json_obj_get_cxstr(value, name); } -CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxmutstr name) { +static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxmutstr name) { return cx_json_obj_get_cxstr(value, cx_strcast(name)); } -CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) { +static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) { return cx_json_obj_get_cxstr(value, cx_str(name)); }