Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/string_cursor_utf8.c
| Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | if (jump != STRCUR_JUMP_NONE) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(0); | BLI_assert(0); | ||||
| } | } | ||||
| } | } | ||||
| /* wchar_t version of BLI_str_cursor_step_utf8 (keep in sync!) | /* UTF32 version of BLI_str_cursor_step_utf8 (keep in sync!) | ||||
| * less complex since it doesn't need to do multi-byte stepping. | * less complex since it doesn't need to do multi-byte stepping. | ||||
| */ | */ | ||||
| /* helper funcs so we can match BLI_str_cursor_step_utf8 */ | /* helper funcs so we can match BLI_str_cursor_step_utf8 */ | ||||
| static bool wchar_t_step_next(const wchar_t *UNUSED(str), size_t maxlen, int *pos) | static bool cursor_step_next_utf32(const char32_t *UNUSED(str), size_t maxlen, int *pos) | ||||
| { | { | ||||
| if ((*pos) >= (int)maxlen) { | if ((*pos) >= (int)maxlen) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| (*pos)++; | (*pos)++; | ||||
| return true; | return true; | ||||
| } | } | ||||
| static bool wchar_t_step_prev(const wchar_t *UNUSED(str), size_t UNUSED(maxlen), int *pos) | static bool cursor_step_prev_utf32(const char32_t *UNUSED(str), size_t UNUSED(maxlen), int *pos) | ||||
| { | { | ||||
| if ((*pos) <= 0) { | if ((*pos) <= 0) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| (*pos)--; | (*pos)--; | ||||
| return true; | return true; | ||||
| } | } | ||||
| void BLI_str_cursor_step_wchar(const wchar_t *str, | void BLI_str_cursor_step_utf32(const char32_t *str, | ||||
| size_t maxlen, | size_t maxlen, | ||||
| int *pos, | int *pos, | ||||
| eStrCursorJumpDirection direction, | eStrCursorJumpDirection direction, | ||||
| eStrCursorJumpType jump, | eStrCursorJumpType jump, | ||||
| bool use_init_step) | bool use_init_step) | ||||
| { | { | ||||
| const int pos_orig = *pos; | const int pos_orig = *pos; | ||||
| if (direction == STRCUR_DIR_NEXT) { | if (direction == STRCUR_DIR_NEXT) { | ||||
| if (use_init_step) { | if (use_init_step) { | ||||
| wchar_t_step_next(str, maxlen, pos); | cursor_step_next_utf32(str, maxlen, pos); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(jump == STRCUR_JUMP_DELIM); | BLI_assert(jump == STRCUR_JUMP_DELIM); | ||||
| } | } | ||||
| if (jump != STRCUR_JUMP_NONE) { | if (jump != STRCUR_JUMP_NONE) { | ||||
| const eStrCursorDelimType delim_type = (*pos) < maxlen ? | const eStrCursorDelimType delim_type = (*pos) < maxlen ? | ||||
| cursor_delim_type_unicode((uint)str[*pos]) : | cursor_delim_type_unicode((uint)str[*pos]) : | ||||
| STRCUR_DELIM_NONE; | STRCUR_DELIM_NONE; | ||||
| /* jump between special characters (/,\,_,-, etc.), | /* jump between special characters (/,\,_,-, etc.), | ||||
| * look at function cursor_delim_type_unicode() for complete | * look at function cursor_delim_type_unicode() for complete | ||||
| * list of special character, ctr -> */ | * list of special character, ctr -> */ | ||||
| while ((*pos) < maxlen) { | while ((*pos) < maxlen) { | ||||
| if (wchar_t_step_next(str, maxlen, pos)) { | if (cursor_step_next_utf32(str, maxlen, pos)) { | ||||
| if ((jump != STRCUR_JUMP_ALL) && | if ((jump != STRCUR_JUMP_ALL) && | ||||
| (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { | (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| break; /* unlikely but just in case */ | break; /* unlikely but just in case */ | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (direction == STRCUR_DIR_PREV) { | else if (direction == STRCUR_DIR_PREV) { | ||||
| if (use_init_step) { | if (use_init_step) { | ||||
| wchar_t_step_prev(str, maxlen, pos); | cursor_step_prev_utf32(str, maxlen, pos); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(jump == STRCUR_JUMP_DELIM); | BLI_assert(jump == STRCUR_JUMP_DELIM); | ||||
| } | } | ||||
| if (jump != STRCUR_JUMP_NONE) { | if (jump != STRCUR_JUMP_NONE) { | ||||
| const eStrCursorDelimType delim_type = (*pos) > 0 ? | const eStrCursorDelimType delim_type = (*pos) > 0 ? | ||||
| cursor_delim_type_unicode((uint)str[(*pos) - 1]) : | cursor_delim_type_unicode((uint)str[(*pos) - 1]) : | ||||
| STRCUR_DELIM_NONE; | STRCUR_DELIM_NONE; | ||||
| /* jump between special characters (/,\,_,-, etc.), | /* jump between special characters (/,\,_,-, etc.), | ||||
| * look at function cursor_delim_type() for complete | * look at function cursor_delim_type() for complete | ||||
| * list of special character, ctr -> */ | * list of special character, ctr -> */ | ||||
| while ((*pos) > 0) { | while ((*pos) > 0) { | ||||
| const int pos_prev = *pos; | const int pos_prev = *pos; | ||||
| if (wchar_t_step_prev(str, maxlen, pos)) { | if (cursor_step_prev_utf32(str, maxlen, pos)) { | ||||
| if ((jump != STRCUR_JUMP_ALL) && | if ((jump != STRCUR_JUMP_ALL) && | ||||
| (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { | (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { | ||||
| /* left only: compensate for index/change in direction */ | /* left only: compensate for index/change in direction */ | ||||
| if ((pos_orig - (*pos)) >= 1) { | if ((pos_orig - (*pos)) >= 1) { | ||||
| *pos = pos_prev; | *pos = pos_prev; | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| Show All 11 Lines | |||||