Skip to content

Commit a76c67c

Browse files
author
Daniel Lemire
committed
Fixing...
1 parent b836164 commit a76c67c

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

doc/basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ The simdjson library has fast functions to validate UTF-8 strings. They are many
200200
bool is_ok = simdjson::validate_utf8(some_string, length);
201201
```
202202

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.
203+
The UTF-8 validation function merely checks that the input is valid UTF-8: it works with strings in general, not just JSON strings.
204204

205205

206206
C++17 Support

include/simdjson/implementation.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,19 @@ WARN_UNUSED bool validate_utf8(const char * buf, size_t length) noexcept;
2626
* @param p the string_view to validate.
2727
* @return true if the string is valid UTF-8.
2828
*/
29-
WARN_UNUSED bool validate_utf8(std::string_view& p) noexcept;
29+
really_inline WARN_UNUSED bool validate_utf8(const std::string_view& p) noexcept {
30+
return validate_utf8(p.data(), p.size());
31+
}
32+
33+
/**
34+
* Validate the UTF-8 string.
35+
*
36+
* @param p the string_view to validate.
37+
* @return true if the string is valid UTF-8.
38+
*/
39+
really_inline WARN_UNUSED bool validate_utf8(const std::string& p) noexcept {
40+
return validate_utf8(p.data(), p.size());
41+
}
3042

3143
namespace dom {
3244
class document;

tests/readme_examples.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ bool is_correct() {
272272
return is_ok;
273273
}
274274

275+
bool is_correct_string_view() {
276+
const char * some_string = "[ 1, 2, 3, 4] ";
277+
size_t length = strlen(some_string);
278+
std::string_view v(some_string, length);
279+
bool is_ok = simdjson::validate_utf8(v);
280+
return is_ok;
281+
}
282+
283+
bool is_correct_string() {
284+
const std::string some_string = "[ 1, 2, 3, 4] ";
285+
bool is_ok = simdjson::validate_utf8(some_string);
286+
return is_ok;
287+
}
288+
275289
int main() {
276290
basics_dom_1();
277291
basics_dom_2();

0 commit comments

Comments
 (0)