diff --git a/_simdjson.cpp b/_simdjson.cpp index ab3ef11..2dba387 100644 --- a/_simdjson.cpp +++ b/_simdjson.cpp @@ -6002,34 +6002,36 @@ inline error_code dom_parser_implementation::allocate(size_t capacity, size_t ma #include namespace _simdjson { + class String { + public: + /** + * Validate the UTF-8 string. + * + * @param buf the string to validate. + * @param len the length of the string in bytes. + * @return true if the string is valid UTF-8. + */ + static _simdjson_warn_unused bool validate_utf8(const char* buf, size_t len) noexcept; + /** + * Validate the UTF-8 string. + * + * @param sv the string_view to validate. + * @return true if the string is valid UTF-8. + */ + static _simdjson_warn_unused bool validate_utf8(const std::string_view sv) noexcept { + return validate_utf8(sv.data(), sv.size()); + } -/** - * Validate the UTF-8 string. - * - * @param buf the string to validate. - * @param len the length of the string in bytes. - * @return true if the string is valid UTF-8. - */ -_simdjson_warn_unused bool validate_utf8(const char * buf, size_t len) noexcept; -/** - * Validate the UTF-8 string. - * - * @param sv the string_view to validate. - * @return true if the string is valid UTF-8. - */ -_simdjson_inline _simdjson_warn_unused bool validate_utf8(const std::string_view sv) noexcept { - return validate_utf8(sv.data(), sv.size()); -} - -/** - * Validate the UTF-8 string. - * - * @param p the string to validate. - * @return true if the string is valid UTF-8. - */ -_simdjson_inline _simdjson_warn_unused bool validate_utf8(const std::string& s) noexcept { - return validate_utf8(s.data(), s.size()); -} + /** + * Validate the UTF-8 string. + * + * @param p the string to validate. + * @return true if the string is valid UTF-8. + */ + static _simdjson_warn_unused bool validate_utf8(const std::string& s) noexcept { + return validate_utf8(s.data(), s.size()); + } + }; /** * An implementation of _simdjson for a particular CPU architecture. @@ -7240,7 +7242,7 @@ SIMDJSON_DLLIMPORTEXPORT internal::atomic_ptr& get_active_ _simdjson_warn_unused error_code minify(const char *buf, size_t len, char *dst, size_t &dst_len) noexcept { return get_active_implementation()->minify(reinterpret_cast(buf), len, reinterpret_cast(dst), dst_len); } -_simdjson_warn_unused bool validate_utf8(const char *buf, size_t len) noexcept { +_simdjson_warn_unused bool String::validate_utf8(const char *buf, size_t len) noexcept { return get_active_implementation()->validate_utf8(buf, len); } const implementation * builtin_implementation() { diff --git a/_simdjson.h b/_simdjson.h index 34c319d..9114802 100644 --- a/_simdjson.h +++ b/_simdjson.h @@ -3218,7 +3218,8 @@ inline error_code dom_parser_implementation::allocate(size_t capacity, size_t ma #include namespace _simdjson { - + class String { + public: /** * Validate the UTF-8 string. * @@ -3226,14 +3227,15 @@ namespace _simdjson { * @param len the length of the string in bytes. * @return true if the string is valid UTF-8. */ - _simdjson_inline _simdjson_warn_unused bool validate_utf8(const char* buf, size_t len) noexcept; + static _simdjson_warn_unused bool validate_utf8(const char* buf, size_t len) noexcept; + /** * Validate the UTF-8 string. * * @param sv the string_view to validate. * @return true if the string is valid UTF-8. */ - _simdjson_inline _simdjson_warn_unused bool validate_utf8(const std::string_view sv) noexcept { + static _simdjson_warn_unused bool validate_utf8(const std::string_view sv) noexcept { return validate_utf8(sv.data(), sv.size()); } @@ -3243,10 +3245,10 @@ namespace _simdjson { * @param p the string to validate. * @return true if the string is valid UTF-8. */ - _simdjson_inline _simdjson_warn_unused bool validate_utf8(const std::string& s) noexcept { + static _simdjson_warn_unused bool validate_utf8(const std::string& s) noexcept { return validate_utf8(s.data(), s.size()); } - + }; /** * An implementation of _simdjson for a particular CPU architecture. * diff --git a/claujson.cpp b/claujson.cpp index e325989..8ec6517 100644 --- a/claujson.cpp +++ b/claujson.cpp @@ -1126,7 +1126,7 @@ namespace claujson { // chk... fallback.. { - bool valid = _simdjson::validate_utf8(reinterpret_cast(buf_src), len); + bool valid = _simdjson::String::validate_utf8(reinterpret_cast(buf_src), len); if (!valid) { free(buf_src); @@ -1168,7 +1168,7 @@ namespace claujson { buf_src[len] = '"'; { - bool valid = _simdjson::validate_utf8(reinterpret_cast(buf_src), len); + bool valid = _simdjson::String::validate_utf8(reinterpret_cast(buf_src), len); if (!valid) { log << warn << "not valid utf8" << "\n"; @@ -6717,7 +6717,7 @@ state = 2; // chk... fallback.. { - bool valid = _simdjson::validate_utf8(reinterpret_cast(buf_src), len); + bool valid = _simdjson::String::validate_utf8(reinterpret_cast(buf_src), len); if (!valid) { free(buf_src); @@ -6751,7 +6751,7 @@ state = 2; buf_src[len] = '"'; { - bool valid = _simdjson::validate_utf8(reinterpret_cast(buf_src), len); + bool valid = _simdjson::String::validate_utf8(reinterpret_cast(buf_src), len); if (!valid) { log << warn << "not valid utf8" << "\n"; @@ -6800,7 +6800,7 @@ state = 2; // chk... fallback.. { - bool valid = _simdjson::validate_utf8(reinterpret_cast(buf_src), len); + bool valid = _simdjson::String::validate_utf8(reinterpret_cast(buf_src), len); if (!valid) { free(buf_src); @@ -6839,7 +6839,7 @@ state = 2; buf_src[len] = '"'; { - bool valid = _simdjson::validate_utf8(reinterpret_cast(buf_src), len); + bool valid = _simdjson::String::validate_utf8(reinterpret_cast(buf_src), len); if (!valid) { log << warn << "not valid utf8" << "\n";