Skip to content

Commit 38bb087

Browse files
committed
With an example.
1 parent 5dbcdf1 commit 38bb087

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

doc/basics.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ In some cases, you may have valid JSON strings that you do not wish to parse but
188188
189189
Though it does not validate the JSON input, it will detect when the document ends with an unterminated string. E.g., it would refuse to minify the string `"this string is not terminated` because of the missing final quote.
190190
191+
192+
UTF-8 validation (alone)
193+
----------------------
194+
195+
The simdjson library has fast functions to validate UTF-8 strings. They are many times faster than most functions commonly found in libraries. You can use our fast functions, even if you do not care about JSON.
196+
197+
```C++
198+
const char * some_string = "[ 1, 2, 3, 4] ";
199+
size_t length = strlen(some_string);
200+
bool is_ok = simdjson::validate_utf8(some_string, length);
201+
```
202+
203+
Though it does not validate the JSON input, it will detect when the document ends with an unterminated string. E.g., it would refuse to minify the string `"this string is not terminated` because of the missing final quote.
204+
205+
191206
C++17 Support
192207
-------------
193208

tests/readme_examples.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@ void minify() {
265265
}
266266
}
267267

268+
bool is_correct() {
269+
const char * some_string = "[ 1, 2, 3, 4] ";
270+
size_t length = strlen(some_string);
271+
bool is_ok = simdjson::validate_utf8(some_string, length);
272+
return is_ok;
273+
}
274+
268275
int main() {
269276
basics_dom_1();
270277
basics_dom_2();

0 commit comments

Comments
 (0)