Add Unicode support to String.to_*_case() methods
This commit is contained in:
parent
16d61427ca
commit
c0aa88ae4f
4 changed files with 1387 additions and 45 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -35,24 +35,43 @@
|
|||
|
||||
#include "char_range.inc"
|
||||
|
||||
#define BSEARCH_CHAR_RANGE(m_array) \
|
||||
int low = 0; \
|
||||
int high = sizeof(m_array) / sizeof(m_array[0]) - 1; \
|
||||
int middle; \
|
||||
\
|
||||
while (low <= high) { \
|
||||
middle = (low + high) / 2; \
|
||||
\
|
||||
if (c < m_array[middle].start) { \
|
||||
high = middle - 1; \
|
||||
} else if (c > m_array[middle].end) { \
|
||||
low = middle + 1; \
|
||||
} else { \
|
||||
return true; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return false
|
||||
|
||||
static _FORCE_INLINE_ bool is_unicode_identifier_start(char32_t c) {
|
||||
for (int i = 0; xid_start[i].start != 0; i++) {
|
||||
if (c >= xid_start[i].start && c <= xid_start[i].end) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
BSEARCH_CHAR_RANGE(xid_start);
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_unicode_identifier_continue(char32_t c) {
|
||||
for (int i = 0; xid_continue[i].start != 0; i++) {
|
||||
if (c >= xid_continue[i].start && c <= xid_continue[i].end) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
BSEARCH_CHAR_RANGE(xid_continue);
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_unicode_upper_case(char32_t c) {
|
||||
BSEARCH_CHAR_RANGE(uppercase_letter);
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ bool is_unicode_lower_case(char32_t c) {
|
||||
BSEARCH_CHAR_RANGE(lowercase_letter);
|
||||
}
|
||||
|
||||
#undef BSEARCH_CHAR_RANGE
|
||||
|
||||
static _FORCE_INLINE_ bool is_ascii_upper_case(char32_t c) {
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1044,17 +1044,17 @@ String String::_camelcase_to_underscore() const {
|
|||
int start_index = 0;
|
||||
|
||||
for (int i = 1; i < size(); i++) {
|
||||
bool is_prev_upper = is_ascii_upper_case(cstr[i - 1]);
|
||||
bool is_prev_lower = is_ascii_lower_case(cstr[i - 1]);
|
||||
bool is_prev_upper = is_unicode_upper_case(cstr[i - 1]);
|
||||
bool is_prev_lower = is_unicode_lower_case(cstr[i - 1]);
|
||||
bool is_prev_digit = is_digit(cstr[i - 1]);
|
||||
|
||||
bool is_curr_upper = is_ascii_upper_case(cstr[i]);
|
||||
bool is_curr_lower = is_ascii_lower_case(cstr[i]);
|
||||
bool is_curr_upper = is_unicode_upper_case(cstr[i]);
|
||||
bool is_curr_lower = is_unicode_lower_case(cstr[i]);
|
||||
bool is_curr_digit = is_digit(cstr[i]);
|
||||
|
||||
bool is_next_lower = false;
|
||||
if (i + 1 < size()) {
|
||||
is_next_lower = is_ascii_lower_case(cstr[i + 1]);
|
||||
is_next_lower = is_unicode_lower_case(cstr[i + 1]);
|
||||
}
|
||||
|
||||
const bool cond_a = is_prev_lower && is_curr_upper; // aA
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue