From 388227b3a59c85250608aeddb09d764ccfad6345 Mon Sep 17 00:00:00 2001 From: vil02 Date: Thu, 1 Feb 2024 19:04:17 +0100 Subject: [PATCH] style: avoid sign conversion in `utf8_to_runes` --- api/utf16.hpp | 2 +- api/utf8.hpp | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api/utf16.hpp b/api/utf16.hpp index 4974ff28e..45cc38d3f 100644 --- a/api/utf16.hpp +++ b/api/utf16.hpp @@ -87,7 +87,7 @@ namespace jule for (std::size_t index = 0; index < s.length();) { jule::I32 rune; - jule::Int n; + std::size_t n; std::tie(rune, n) = jule::utf8_decode_rune_str(str + index, s.length() - index); index += n; diff --git a/api/utf8.hpp b/api/utf8.hpp index aa1365391..8ed6aee9e 100644 --- a/api/utf8.hpp +++ b/api/utf8.hpp @@ -52,7 +52,7 @@ namespace jule struct UTF8AcceptRange; std::string runes_to_utf8(const std::vector &s) noexcept; - std::tuple utf8_decode_rune_str(const char *s, const jule::Int &len); + std::tuple utf8_decode_rune_str(const char *s, const std::size_t len); std::vector utf8_rune_to_bytes(const jule::I32 &r); // Definitions @@ -340,10 +340,10 @@ namespace jule return buffer; } - std::tuple - utf8_decode_rune_str(const char *s, const jule::Int &len) + std::tuple + utf8_decode_rune_str(const char *s, const std::size_t len) { - if (len < 1) + if (len == 0) return std::make_tuple(jule::UTF8_RUNE_ERROR, 0); const auto s0 = static_cast(s[0]); @@ -356,27 +356,27 @@ namespace jule 1); } - const auto sz = static_cast(x & 7); + const auto sz = static_cast(x & 7); const struct jule::UTF8AcceptRange accept = jule::utf8_accept_ranges[x >> 4]; if (len < sz) - return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); + return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); const auto s1 = static_cast(s[1]); if (s1 < accept.lo || accept.hi < s1) - return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); + return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); if (sz <= 2) - return std::make_tuple( + return std::make_tuple( (static_cast(s0 & jule::UTF8_MASK2) << 6) | static_cast(s1 & jule::UTF8_MASKX), 2); const auto s2 = static_cast(s[2]); if (s2 < jule::UTF8_LOCB || jule::UTF8_HICB < s2) - return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); + return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); if (sz <= 3) - return std::make_tuple( + return std::make_tuple( (static_cast(s0 & jule::UTF8_MASK3) << 12) | (static_cast(s1 & jule::UTF8_MASKX) << 6) | static_cast(s2 & jule::UTF8_MASKX), @@ -384,7 +384,7 @@ namespace jule const auto s3 = static_cast(s[3]); if (s3 < jule::UTF8_LOCB || jule::UTF8_HICB < s3) - return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); + return std::make_tuple(jule::UTF8_RUNE_ERROR, 1); return std::make_tuple((static_cast(s0 & jule::UTF8_MASK4) << 18) | (static_cast(s1 & jule::UTF8_MASKX) << 12) |