@@ -62,21 +62,42 @@ class element {
6262 */
6363 inline simdjson_result<object> get_object () const noexcept ;
6464 /* *
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.
6668 *
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.
6874 *
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
7079 * be invalidated the next time it parses a document or when it is destroyed.
7180 * Returns INCORRECT_TYPE if the JSON element is not a string.
7281 */
7382 inline simdjson_result<const char *> get_c_str () const noexcept ;
7483 /* *
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.
7697 *
7798 * Equivalent to get<std::string_view>().
7899 *
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
80101 * parses a document or when it is destroyed.
81102 * Returns INCORRECT_TYPE if the JSON element is not a string.
82103 */
@@ -253,7 +274,9 @@ class element {
253274 inline operator bool () const noexcept (false );
254275
255276 /* *
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.
257280 *
258281 * Does *not* convert other types to a string; requires that the JSON type of the element was
259282 * an actual string.
@@ -264,7 +287,7 @@ class element {
264287 inline explicit operator const char *() const noexcept (false );
265288
266289 /* *
267- * Read this element as a null-terminated string.
290+ * Read this element as a null-terminated UTF-8 string.
268291 *
269292 * Does *not* convert other types to a string; requires that the JSON type of the element was
270293 * an actual string.
0 commit comments