diff --git a/AK/Utf8View.cpp b/AK/Utf8View.cpp index f43ee1b0cd..ede1eb2391 100644 --- a/AK/Utf8View.cpp +++ b/AK/Utf8View.cpp @@ -57,7 +57,7 @@ const unsigned char* Utf8View::end_ptr() const Utf8CodepointIterator Utf8View::begin() const { - return { begin_ptr(), (int)m_string.length() }; + return { begin_ptr(), m_string.length() }; } Utf8CodepointIterator Utf8View::end() const @@ -81,7 +81,7 @@ Utf8View Utf8View::substring_view(int byte_offset, int byte_length) const static inline bool decode_first_byte( unsigned char byte, - int& out_code_point_length_in_bytes, + size_t& out_code_point_length_in_bytes, u32& out_value) { if ((byte & 128) == 0) { @@ -115,13 +115,13 @@ bool Utf8View::validate(size_t& valid_bytes) const { valid_bytes = 0; for (auto ptr = begin_ptr(); ptr < end_ptr(); ptr++) { - int code_point_length_in_bytes; + size_t code_point_length_in_bytes; u32 value; bool first_byte_makes_sense = decode_first_byte(*ptr, code_point_length_in_bytes, value); if (!first_byte_makes_sense) return false; - for (int i = 1; i < code_point_length_in_bytes; i++) { + for (size_t i = 1; i < code_point_length_in_bytes; i++) { ptr++; if (ptr >= end_ptr()) return false; @@ -144,7 +144,7 @@ size_t Utf8View::calculate_length() const return length; } -Utf8CodepointIterator::Utf8CodepointIterator(const unsigned char* ptr, int length) +Utf8CodepointIterator::Utf8CodepointIterator(const unsigned char* ptr, size_t length) : m_ptr(ptr) , m_length(length) { @@ -164,7 +164,7 @@ Utf8CodepointIterator& Utf8CodepointIterator::operator++() { ASSERT(m_length > 0); - int code_point_length_in_bytes = 0; + size_t code_point_length_in_bytes = 0; u32 value; bool first_byte_makes_sense = decode_first_byte(*m_ptr, code_point_length_in_bytes, value); @@ -177,10 +177,10 @@ Utf8CodepointIterator& Utf8CodepointIterator::operator++() return *this; } -int Utf8CodepointIterator::code_point_length_in_bytes() const +size_t Utf8CodepointIterator::code_point_length_in_bytes() const { ASSERT(m_length > 0); - int code_point_length_in_bytes = 0; + size_t code_point_length_in_bytes = 0; u32 value; bool first_byte_makes_sense = decode_first_byte(*m_ptr, code_point_length_in_bytes, value); ASSERT(first_byte_makes_sense); @@ -192,17 +192,17 @@ u32 Utf8CodepointIterator::operator*() const ASSERT(m_length > 0); u32 code_point_value_so_far = 0; - int code_point_length_in_bytes = 0; + size_t code_point_length_in_bytes = 0; bool first_byte_makes_sense = decode_first_byte(m_ptr[0], code_point_length_in_bytes, code_point_value_so_far); if (!first_byte_makes_sense) - dbgln("First byte doesn't make sense, bytes: {}", StringView { (const char*)m_ptr, (size_t)m_length }); + dbgln("First byte doesn't make sense, bytes: {}", StringView { (const char*)m_ptr, m_length }); ASSERT(first_byte_makes_sense); if (code_point_length_in_bytes > m_length) dbgln("Not enough bytes (need {}, have {}), first byte is: {:#02x}, '{}'", code_point_length_in_bytes, m_length, m_ptr[0], (const char*)m_ptr); ASSERT(code_point_length_in_bytes <= m_length); - for (int offset = 1; offset < code_point_length_in_bytes; offset++) { + for (size_t offset = 1; offset < code_point_length_in_bytes; offset++) { ASSERT(m_ptr[offset] >> 6 == 2); code_point_value_so_far <<= 6; code_point_value_so_far |= m_ptr[offset] & 63; diff --git a/AK/Utf8View.h b/AK/Utf8View.h index bfb5d489b3..fe37298e63 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -50,13 +50,13 @@ public: return m_ptr - other.m_ptr; } - int code_point_length_in_bytes() const; - bool done() const { return !m_length; } + size_t code_point_length_in_bytes() const; + bool done() const { return m_length == 0; } private: - Utf8CodepointIterator(const unsigned char*, int); + Utf8CodepointIterator(const unsigned char*, size_t); const unsigned char* m_ptr { nullptr }; - int m_length { -1 }; + size_t m_length; }; class Utf8View {