Skip to content

Commit

Permalink
Optimise unicode::utf8_char_len & utf16_char_len
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jul 1, 2024
1 parent e945c97 commit 83ca134
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions soup/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,19 @@ NAMESPACE_SOUP
size_t unicode::utf8_char_len(const std::string& str) noexcept
{
size_t char_len = 0;
for (const auto& c : str)
for (size_t i = 0; i != str.size(); ++i)
{
if (!UTF8_IS_CONTINUATION(c))
{
++char_len;
}
char_len += !UTF8_IS_CONTINUATION(str[i]);
}
return char_len;
}

size_t unicode::utf16_char_len(const UTF16_STRING_TYPE& str) noexcept
{
size_t char_len = 0;
for (const auto& c : str)
for (size_t i = 0; i != str.size(); ++i)
{
SOUP_IF_LIKELY (!UTF16_IS_LOW_SURROGATE(c))
{
++char_len;
}
char_len += !UTF16_IS_LOW_SURROGATE(str[i]);
}
return char_len;
}
Expand Down

0 comments on commit 83ca134

Please sign in to comment.