diff --git a/include/simdjson/implementation.h b/include/simdjson/implementation.h index c828dc97..4eb6e73c 100644 --- a/include/simdjson/implementation.h +++ b/include/simdjson/implementation.h @@ -83,6 +83,18 @@ public: * @return the error code, or SUCCESS if there was no error. */ WARN_UNUSED virtual error_code minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept = 0; + + + /** + * Validate the UTF-8 string. + * + * Overridden by each implementation. + * + * @param buf the string to validate. + * @param len the length of the string in bytes. + * @return true if and only if the string is valid UTF-8. + */ + WARN_UNUSED virtual bool utf8_validate(const char *buf, size_t len) const noexcept = 0; protected: /** @private Construct an implementation with the given name and description. For subclasses. */ diff --git a/src/arm64/implementation.h b/src/arm64/implementation.h index 32d998d4..5f679efb 100644 --- a/src/arm64/implementation.h +++ b/src/arm64/implementation.h @@ -18,7 +18,7 @@ public: std::unique_ptr& dst ) const noexcept final; WARN_UNUSED error_code minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept final; - WARN_UNUSED bool utf8_validate(const char *buf, size_t len) const noexcept;//mark final + WARN_UNUSED bool utf8_validate(const char *buf, size_t len) const noexcept final; }; } // namespace arm64 diff --git a/src/fallback/implementation.h b/src/fallback/implementation.h index ee099d8d..d05d594a 100644 --- a/src/fallback/implementation.h +++ b/src/fallback/implementation.h @@ -22,7 +22,7 @@ public: std::unique_ptr& dst ) const noexcept final; WARN_UNUSED error_code minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept final; - WARN_UNUSED bool utf8_validate(const char *buf, size_t len) const noexcept;//mark final + WARN_UNUSED bool utf8_validate(const char *buf, size_t len) const noexcept final; }; } // namespace fallback diff --git a/src/haswell/implementation.h b/src/haswell/implementation.h index 7a2dbe9e..e50d970b 100644 --- a/src/haswell/implementation.h +++ b/src/haswell/implementation.h @@ -20,7 +20,7 @@ public: std::unique_ptr& dst ) const noexcept final; WARN_UNUSED error_code minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept final; - WARN_UNUSED bool utf8_validate(const char *buf, size_t len) const noexcept;//mark final + WARN_UNUSED bool utf8_validate(const char *buf, size_t len) const noexcept final; }; } // namespace haswell diff --git a/src/implementation.cpp b/src/implementation.cpp index 1c5c516d..32ee2666 100644 --- a/src/implementation.cpp +++ b/src/implementation.cpp @@ -48,7 +48,9 @@ public: WARN_UNUSED error_code minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept final { return set_best()->minify(buf, len, dst, dst_len); } - + WARN_UNUSED bool utf8_validate(const char * buf, size_t len) const noexcept final override { + return set_best()->utf8_validate(buf, len); + } really_inline detect_best_supported_implementation_on_first_use() noexcept : implementation("best_supported_detector", "Detects the best supported implementation and sets it", 0) {} private: const implementation *set_best() const noexcept; @@ -83,10 +85,12 @@ public: ) const noexcept final { return UNSUPPORTED_ARCHITECTURE; } - WARN_UNUSED error_code minify(const uint8_t *, size_t, uint8_t *, size_t &) const noexcept final { + WARN_UNUSED error_code minify(const uint8_t *, size_t, uint8_t *, size_t &) const noexcept final override { return UNSUPPORTED_ARCHITECTURE; } - + WARN_UNUSED bool utf8_validate(const char *, size_t) const noexcept final override { + return false; // just refuse the validate + } unsupported_implementation() : implementation("unsupported", "Unsupported CPU (no detected SIMD instructions)", 0) {} }; diff --git a/src/westmere/implementation.h b/src/westmere/implementation.h index a960a3d6..43847810 100644 --- a/src/westmere/implementation.h +++ b/src/westmere/implementation.h @@ -19,7 +19,7 @@ public: std::unique_ptr& dst ) const noexcept final; WARN_UNUSED error_code minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept final; - WARN_UNUSED bool utf8_validate(const char *buf, size_t len) const noexcept;//mark final + WARN_UNUSED bool utf8_validate(const char *buf, size_t len) const noexcept final; }; } // namespace westmere