From 64559e5a17e69c9dbbffe239e694a28980026d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Mon, 4 Nov 2024 20:49:51 +0200 Subject: [PATCH] Change kReplacementCharUtf8 type to constexpr string_view --- include/upa/url_utf.h | 7 +++++-- src/url_utf.cpp | 7 ++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/upa/url_utf.h b/include/upa/url_utf.h index c367271..915c0e1 100644 --- a/include/upa/url_utf.h +++ b/include/upa/url_utf.h @@ -9,6 +9,7 @@ #include "url_result.h" #include // uint8_t, uint32_t #include +#include namespace upa { @@ -44,7 +45,9 @@ class url_utf { static constexpr bool read_code_point(const char16_t*& first, const char16_t* last, uint32_t& code_point) noexcept; static constexpr bool read_code_point(const char32_t*& first, const char32_t* last, uint32_t& code_point) noexcept; private: - const static char kReplacementCharUtf8[]; + // Replacement character (U+FFFD) + static inline constexpr std::string_view kReplacementCharUtf8{ "\xEF\xBF\xBD" }; + const static uint8_t k_U8_LEAD3_T1_BITS[16]; const static uint8_t k_U8_LEAD4_T1_BITS[16]; }; @@ -95,7 +98,7 @@ inline void url_utf::read_char_append_utf8(const char*& it, const char* last, st if (read_code_point(it, last, code_point)) output.append(start, it); else - output.append(static_cast(kReplacementCharUtf8)); + output.append(kReplacementCharUtf8); } // ------------------------------------------------------------------------ diff --git a/src/url_utf.cpp b/src/url_utf.cpp index 68c3d48..833084e 100644 --- a/src/url_utf.cpp +++ b/src/url_utf.cpp @@ -38,7 +38,7 @@ void url_utf::check_fix_utf8(std::string& str) { // replace invalid UTF-8 byte sequences with replacement char std::string buff; buff.append(first, ptr); - buff.append(static_cast(kReplacementCharUtf8)); + buff.append(kReplacementCharUtf8); const char* bgn = it; ptr = it; @@ -47,7 +47,7 @@ void url_utf::check_fix_utf8(std::string& str) { ptr = it; } else { buff.append(bgn, ptr); - buff.append(static_cast(kReplacementCharUtf8)); + buff.append(kReplacementCharUtf8); bgn = it; ptr = it; } @@ -93,9 +93,6 @@ int url_utf::compare_by_code_units(const char* first1, const char* last1, const return 0; } -// Replacement character -const char url_utf::kReplacementCharUtf8[] = "\xEF\xBF\xBD"; - // // (c) 2016 and later: Unicode, Inc. and others. // License & terms of use: https://www.unicode.org/copyright.html