|
1 | | -/* auto-generated on 2023-05-07 19:12:14 -0400. Do not edit! */ |
| 1 | +/* auto-generated on 2023-08-29 15:28:19 -0400. Do not edit! */ |
2 | 2 | /* begin file src/idna.cpp */ |
3 | 3 | /* begin file src/unicode_transcoding.cpp */ |
4 | 4 |
|
| 5 | +#include <algorithm> |
5 | 6 | #include <cstdint> |
6 | 7 | #include <cstring> |
7 | 8 |
|
@@ -108,38 +109,22 @@ size_t utf8_length_from_utf32(const char32_t* buf, size_t len) { |
108 | 109 | // We are not BOM aware. |
109 | 110 | const uint32_t* p = reinterpret_cast<const uint32_t*>(buf); |
110 | 111 | size_t counter{0}; |
111 | | - for (size_t i = 0; i < len; i++) { |
112 | | - /** ASCII **/ |
113 | | - if (p[i] <= 0x7F) { |
114 | | - counter++; |
115 | | - } |
116 | | - /** two-byte **/ |
117 | | - else if (p[i] <= 0x7FF) { |
118 | | - counter += 2; |
119 | | - } |
120 | | - /** three-byte **/ |
121 | | - else if (p[i] <= 0xFFFF) { |
122 | | - counter += 3; |
123 | | - } |
124 | | - /** four-bytes **/ |
125 | | - else { |
126 | | - counter += 4; |
127 | | - } |
| 112 | + for (size_t i = 0; i != len; ++i) { |
| 113 | + ++counter; // ASCII |
| 114 | + counter += static_cast<size_t>(p[i] > 0x7F); // two-byte |
| 115 | + counter += static_cast<size_t>(p[i] > 0x7FF); // three-byte |
| 116 | + counter += static_cast<size_t>(p[i] > 0xFFFF); // four-bytes |
128 | 117 | } |
129 | 118 | return counter; |
130 | 119 | } |
131 | 120 |
|
132 | 121 | size_t utf32_length_from_utf8(const char* buf, size_t len) { |
133 | 122 | const int8_t* p = reinterpret_cast<const int8_t*>(buf); |
134 | | - size_t counter{0}; |
135 | | - for (size_t i = 0; i < len; i++) { |
| 123 | + return std::count_if(p, std::next(p, len), [](int8_t c) { |
136 | 124 | // -65 is 0b10111111, anything larger in two-complement's |
137 | 125 | // should start a new code point. |
138 | | - if (p[i] > -65) { |
139 | | - counter++; |
140 | | - } |
141 | | - } |
142 | | - return counter; |
| 126 | + return c > -65; |
| 127 | + }); |
143 | 128 | } |
144 | 129 |
|
145 | 130 | size_t utf32_to_utf8(const char32_t* buf, size_t len, char* utf8_output) { |
@@ -9407,14 +9392,14 @@ bool constexpr begins_with(std::u32string_view view, |
9407 | 9392 | if (view.size() < prefix.size()) { |
9408 | 9393 | return false; |
9409 | 9394 | } |
9410 | | - return view.substr(0, prefix.size()) == prefix; |
| 9395 | + return std::equal(prefix.begin(), prefix.end(), view.begin()); |
9411 | 9396 | } |
9412 | 9397 |
|
9413 | 9398 | bool constexpr begins_with(std::string_view view, std::string_view prefix) { |
9414 | 9399 | if (view.size() < prefix.size()) { |
9415 | 9400 | return false; |
9416 | 9401 | } |
9417 | | - return view.substr(0, prefix.size()) == prefix; |
| 9402 | + return std::equal(prefix.begin(), prefix.end(), view.begin()); |
9418 | 9403 | } |
9419 | 9404 |
|
9420 | 9405 | bool constexpr is_ascii(std::u32string_view view) { |
|
0 commit comments