Commit b2c4a5db authored by Max Kellermann's avatar Max Kellermann

util/UTF8: use `uint8_t` instead of `unsigned char`

parent cadfccfd
...@@ -33,17 +33,19 @@ ...@@ -33,17 +33,19 @@
#include <algorithm> #include <algorithm>
#include <stdint.h>
/** /**
* Is this a leading byte that is followed by 1 continuation byte? * Is this a leading byte that is followed by 1 continuation byte?
*/ */
static constexpr bool static constexpr bool
IsLeading1(unsigned char ch) noexcept IsLeading1(uint8_t ch) noexcept
{ {
return (ch & 0xe0) == 0xc0; return (ch & 0xe0) == 0xc0;
} }
static constexpr unsigned char static constexpr uint8_t
MakeLeading1(unsigned char value) noexcept MakeLeading1(uint8_t value) noexcept
{ {
return 0xc0 | value; return 0xc0 | value;
} }
...@@ -52,13 +54,13 @@ MakeLeading1(unsigned char value) noexcept ...@@ -52,13 +54,13 @@ MakeLeading1(unsigned char value) noexcept
* Is this a leading byte that is followed by 2 continuation byte? * Is this a leading byte that is followed by 2 continuation byte?
*/ */
static constexpr bool static constexpr bool
IsLeading2(unsigned char ch) noexcept IsLeading2(uint8_t ch) noexcept
{ {
return (ch & 0xf0) == 0xe0; return (ch & 0xf0) == 0xe0;
} }
static constexpr unsigned char static constexpr uint8_t
MakeLeading2(unsigned char value) noexcept MakeLeading2(uint8_t value) noexcept
{ {
return 0xe0 | value; return 0xe0 | value;
} }
...@@ -67,13 +69,13 @@ MakeLeading2(unsigned char value) noexcept ...@@ -67,13 +69,13 @@ MakeLeading2(unsigned char value) noexcept
* Is this a leading byte that is followed by 3 continuation byte? * Is this a leading byte that is followed by 3 continuation byte?
*/ */
static constexpr bool static constexpr bool
IsLeading3(unsigned char ch) noexcept IsLeading3(uint8_t ch) noexcept
{ {
return (ch & 0xf8) == 0xf0; return (ch & 0xf8) == 0xf0;
} }
static constexpr unsigned char static constexpr uint8_t
MakeLeading3(unsigned char value) noexcept MakeLeading3(uint8_t value) noexcept
{ {
return 0xf0 | value; return 0xf0 | value;
} }
...@@ -82,13 +84,13 @@ MakeLeading3(unsigned char value) noexcept ...@@ -82,13 +84,13 @@ MakeLeading3(unsigned char value) noexcept
* Is this a leading byte that is followed by 4 continuation byte? * Is this a leading byte that is followed by 4 continuation byte?
*/ */
static constexpr bool static constexpr bool
IsLeading4(unsigned char ch) noexcept IsLeading4(uint8_t ch) noexcept
{ {
return (ch & 0xfc) == 0xf8; return (ch & 0xfc) == 0xf8;
} }
static constexpr unsigned char static constexpr uint8_t
MakeLeading4(unsigned char value) noexcept MakeLeading4(uint8_t value) noexcept
{ {
return 0xf8 | value; return 0xf8 | value;
} }
...@@ -97,19 +99,19 @@ MakeLeading4(unsigned char value) noexcept ...@@ -97,19 +99,19 @@ MakeLeading4(unsigned char value) noexcept
* Is this a leading byte that is followed by 5 continuation byte? * Is this a leading byte that is followed by 5 continuation byte?
*/ */
static constexpr bool static constexpr bool
IsLeading5(unsigned char ch) noexcept IsLeading5(uint8_t ch) noexcept
{ {
return (ch & 0xfe) == 0xfc; return (ch & 0xfe) == 0xfc;
} }
static constexpr unsigned char static constexpr uint8_t
MakeLeading5(unsigned char value) noexcept MakeLeading5(uint8_t value) noexcept
{ {
return 0xfc | value; return 0xfc | value;
} }
static constexpr bool static constexpr bool
IsContinuation(unsigned char ch) noexcept IsContinuation(uint8_t ch) noexcept
{ {
return (ch & 0xc0) == 0x80; return (ch & 0xc0) == 0x80;
} }
...@@ -117,8 +119,8 @@ IsContinuation(unsigned char ch) noexcept ...@@ -117,8 +119,8 @@ IsContinuation(unsigned char ch) noexcept
/** /**
* Generate a continuation byte of the low 6 bit. * Generate a continuation byte of the low 6 bit.
*/ */
static constexpr unsigned char static constexpr uint8_t
MakeContinuation(unsigned char value) noexcept MakeContinuation(uint8_t value) noexcept
{ {
return 0x80 | (value & 0x3f); return 0x80 | (value & 0x3f);
} }
...@@ -127,7 +129,7 @@ bool ...@@ -127,7 +129,7 @@ bool
ValidateUTF8(const char *p) noexcept ValidateUTF8(const char *p) noexcept
{ {
for (; *p != 0; ++p) { for (; *p != 0; ++p) {
unsigned char ch = *p; uint8_t ch = *p;
if (IsASCII(ch)) if (IsASCII(ch))
continue; continue;
...@@ -221,7 +223,7 @@ InnerSequenceLengthUTF8(const char *p) noexcept ...@@ -221,7 +223,7 @@ InnerSequenceLengthUTF8(const char *p) noexcept
size_t size_t
SequenceLengthUTF8(const char *p) noexcept SequenceLengthUTF8(const char *p) noexcept
{ {
const unsigned char ch = *p++; const uint8_t ch = *p++;
if (IsASCII(ch)) if (IsASCII(ch))
return 1; return 1;
...@@ -272,7 +274,7 @@ Latin1ToUTF8(const char *gcc_restrict src, char *gcc_restrict buffer, ...@@ -272,7 +274,7 @@ Latin1ToUTF8(const char *gcc_restrict src, char *gcc_restrict buffer,
char *q = std::copy(src, p, buffer); char *q = std::copy(src, p, buffer);
while (*p != 0) { while (*p != 0) {
unsigned char ch = *p++; uint8_t ch = *p++;
if (IsASCII(ch)) { if (IsASCII(ch)) {
*q++ = ch; *q++ = ch;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment