Skip to content

Commit 14b0f35

Browse files
committed
chore: update ada::idna package
1 parent b0d2c47 commit 14b0f35

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

include/ada/ada_idna.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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! */
22
/* begin file include/idna.h */
33
#ifndef ADA_IDNA_H
44
#define ADA_IDNA_H

src/ada_idna.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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! */
22
/* begin file src/idna.cpp */
33
/* begin file src/unicode_transcoding.cpp */
44

5+
#include <algorithm>
56
#include <cstdint>
67
#include <cstring>
78

@@ -108,38 +109,22 @@ size_t utf8_length_from_utf32(const char32_t* buf, size_t len) {
108109
// We are not BOM aware.
109110
const uint32_t* p = reinterpret_cast<const uint32_t*>(buf);
110111
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
128117
}
129118
return counter;
130119
}
131120

132121
size_t utf32_length_from_utf8(const char* buf, size_t len) {
133122
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) {
136124
// -65 is 0b10111111, anything larger in two-complement's
137125
// should start a new code point.
138-
if (p[i] > -65) {
139-
counter++;
140-
}
141-
}
142-
return counter;
126+
return c > -65;
127+
});
143128
}
144129

145130
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,
94079392
if (view.size() < prefix.size()) {
94089393
return false;
94099394
}
9410-
return view.substr(0, prefix.size()) == prefix;
9395+
return std::equal(prefix.begin(), prefix.end(), view.begin());
94119396
}
94129397

94139398
bool constexpr begins_with(std::string_view view, std::string_view prefix) {
94149399
if (view.size() < prefix.size()) {
94159400
return false;
94169401
}
9417-
return view.substr(0, prefix.size()) == prefix;
9402+
return std::equal(prefix.begin(), prefix.end(), view.begin());
94189403
}
94199404

94209405
bool constexpr is_ascii(std::u32string_view view) {

0 commit comments

Comments
 (0)