Skip to content

Commit 9535c5b

Browse files
author
Sriya Pratipati
committed
cleaned up code
1 parent a188c4b commit 9535c5b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

libc/src/__support/wchar/character_converter.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,29 @@ int CharacterConverter::push(char8_t utf8_byte) {
2727
// Checking the first byte if first push
2828
if (state->bytes_processed == 0 && state->total_bytes == 0) {
2929
state->partial = static_cast<char32_t>(0);
30+
int numOnes = cpp::countl_one(utf8_byte);
31+
switch (numOnes) {
3032
// 1 byte total
31-
if (cpp::countl_one(utf8_byte) == 0) {
33+
case 0:
3234
state->total_bytes = 1;
33-
}
35+
break;
3436
// 2 bytes total
35-
else if (cpp::countl_one(utf8_byte) == 2) {
37+
case 2:
3638
state->total_bytes = 2;
3739
utf8_byte &= 0x1F;
38-
}
40+
break;
3941
// 3 bytes total
40-
else if (cpp::countl_one(utf8_byte) == 3) {
42+
case 3:
4143
state->total_bytes = 3;
4244
utf8_byte &= 0x0F;
43-
}
45+
break;
4446
// 4 bytes total
45-
else if (cpp::countl_one(utf8_byte) == 4) {
47+
case 4:
4648
state->total_bytes = 4;
4749
utf8_byte &= 0x07;
48-
}
49-
// Invalid byte -> reset mbstate
50-
else {
50+
break;
51+
// Invalid first byte
52+
default:
5153
return -1;
5254
}
5355
state->partial = static_cast<char32_t>(utf8_byte);

0 commit comments

Comments
 (0)