Skip to content

Commit

Permalink
Change kReplacementCharUtf8 type to constexpr string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Nov 4, 2024
1 parent 2758da8 commit 64559e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 5 additions & 2 deletions include/upa/url_utf.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "url_result.h"
#include <cstdint> // uint8_t, uint32_t
#include <string>
#include <string_view>


namespace upa {
Expand Down Expand Up @@ -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];
};
Expand Down Expand Up @@ -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<const char*>(kReplacementCharUtf8));
output.append(kReplacementCharUtf8);
}

// ------------------------------------------------------------------------
Expand Down
7 changes: 2 additions & 5 deletions src/url_utf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*>(kReplacementCharUtf8));
buff.append(kReplacementCharUtf8);

const char* bgn = it;
ptr = it;
Expand All @@ -47,7 +47,7 @@ void url_utf::check_fix_utf8(std::string& str) {
ptr = it;
} else {
buff.append(bgn, ptr);
buff.append(static_cast<const char*>(kReplacementCharUtf8));
buff.append(kReplacementCharUtf8);
bgn = it;
ptr = it;
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 64559e5

Please sign in to comment.