rename codepoint to decode
parent
b350eced7e
commit
c4f67b08b9
|
@ -715,7 +715,7 @@ namespace utf {
|
|||
* The string is advanced past the UTF-8 character in the front.
|
||||
* If the decoding fails, `false` is returned, otherwise it's `true`.
|
||||
*/
|
||||
bool codepoint(string_range &r, char32_t &ret) noexcept;
|
||||
bool decode(string_range &r, char32_t &ret) noexcept;
|
||||
|
||||
/* @brief Get the number of Unicode code points in a string.
|
||||
*
|
||||
|
@ -774,7 +774,7 @@ namespace utf {
|
|||
|
||||
private:
|
||||
void advance() {
|
||||
if (char32_t ret; !codepoint(p_range, ret)) {
|
||||
if (char32_t ret; !decode(p_range, ret)) {
|
||||
/* range is unchanged */
|
||||
p_current = -1;
|
||||
throw utf_error{"UTF-8 decoding failed"};
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace utf {
|
|||
|
||||
constexpr std::uint32_t MaxCodepoint = 0x10FFFF;
|
||||
|
||||
static inline bool codepoint_dec(string_range &r, char32_t &cret) noexcept {
|
||||
static inline bool u8_decode(string_range &r, char32_t &cret) noexcept {
|
||||
static const std::uint32_t ulim[] = { 0xFF, 0x7F, 0x7FF, 0xFFFF };
|
||||
if (r.empty()) {
|
||||
return false;
|
||||
|
@ -61,13 +61,13 @@ static inline bool codepoint_dec(string_range &r, char32_t &cret) noexcept {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool codepoint(string_range &r, char32_t &ret) noexcept {
|
||||
return codepoint_dec(r, ret);
|
||||
bool decode(string_range &r, char32_t &ret) noexcept {
|
||||
return u8_decode(r, ret);
|
||||
}
|
||||
|
||||
std::size_t length(string_range r, string_range &cont) noexcept {
|
||||
std::size_t ret = 0;
|
||||
for (char32_t ch = U'\0'; codepoint_dec(r, ch); ++ret) {
|
||||
for (char32_t ch = U'\0'; u8_decode(r, ch); ++ret) {
|
||||
continue;
|
||||
}
|
||||
cont = r;
|
||||
|
|
Loading…
Reference in New Issue