@@ -62,21 +62,42 @@ class element {
62
62
*/
63
63
inline simdjson_result<object> get_object () const noexcept ;
64
64
/* *
65
- * Cast this element to a string.
65
+ * Cast this element to a null-terminated C string.
66
+ *
67
+ * The string is guaranteed to be valid UTF-8.
66
68
*
67
- * Equivalent to get<const char *>().
69
+ * The get_c_str() function is equivalent to get<const char *>().
70
+ *
71
+ * The length of the string is given by get_string_length(). Because JSON strings
72
+ * may contain null characters, it may be incorrect to use strlen to determine the
73
+ * string length.
68
74
*
69
- * @returns An pointer to a null-terminated string. This string is stored in the parser and will
75
+ * It is possible to get a single string_view instance which represents both the string
76
+ * content and its length: see get_string().
77
+ *
78
+ * @returns A pointer to a null-terminated UTF-8 string. This string is stored in the parser and will
70
79
* be invalidated the next time it parses a document or when it is destroyed.
71
80
* Returns INCORRECT_TYPE if the JSON element is not a string.
72
81
*/
73
82
inline simdjson_result<const char *> get_c_str () const noexcept ;
74
83
/* *
75
- * Cast this element to a string.
84
+ * Gives the length in bytes of the string.
85
+ *
86
+ * It is possible to get a single string_view instance which represents both the string
87
+ * content and its length: see get_string().
88
+ *
89
+ * @returns A string length in bytes.
90
+ * Returns INCORRECT_TYPE if the JSON element is not a string.
91
+ */
92
+ inline simdjson_result<size_t > get_string_length () const noexcept ;
93
+ /* *
94
+ * Cast this element to a string.
95
+ *
96
+ * The string is guaranteed to be valid UTF-8.
76
97
*
77
98
* Equivalent to get<std::string_view>().
78
99
*
79
- * @returns A string. The string is stored in the parser and will be invalidated the next time it
100
+ * @returns An UTF-8 string. The string is stored in the parser and will be invalidated the next time it
80
101
* parses a document or when it is destroyed.
81
102
* Returns INCORRECT_TYPE if the JSON element is not a string.
82
103
*/
@@ -253,7 +274,9 @@ class element {
253
274
inline operator bool () const noexcept (false );
254
275
255
276
/* *
256
- * Read this element as a null-terminated string.
277
+ * Read this element as a null-terminated UTF-8 string.
278
+ *
279
+ * Be mindful that JSON allows strings to contain null characters.
257
280
*
258
281
* Does *not* convert other types to a string; requires that the JSON type of the element was
259
282
* an actual string.
@@ -264,7 +287,7 @@ class element {
264
287
inline explicit operator const char *() const noexcept (false );
265
288
266
289
/* *
267
- * Read this element as a null-terminated string.
290
+ * Read this element as a null-terminated UTF-8 string.
268
291
*
269
292
* Does *not* convert other types to a string; requires that the JSON type of the element was
270
293
* an actual string.
0 commit comments