diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-08-06 10:16:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-08-06 14:59:13 +0300 |
commit | dcad1eb03ccc0782229d81cdbeaa71c035c09955 (patch) | |
tree | c06a59d5751331a2a5eda36d27ba66a2fc9357f3 /source/blender/blenkernel | |
parent | 8b2810a32f094f4d95663d630700c6f147703ad6 (diff) |
Cleanup: move utf8 offset conversion into BLI_string_utf8
There isn't anything specific to text data with these functions.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 52 |
2 files changed, 4 insertions, 52 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index f018e912945..65aa43ced7c 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -59,10 +59,6 @@ void txt_order_cursors(struct Text *text, const bool reverse); int txt_find_string(struct Text *text, const char *findstr, int wrap, int match_case); bool txt_has_sel(struct Text *text); int txt_get_span(struct TextLine *from, struct TextLine *to); -int txt_utf8_offset_to_index(const char *str, int offset); -int txt_utf8_index_to_offset(const char *str, int index); -int txt_utf8_offset_to_column(const char *str, int offset); -int txt_utf8_column_to_offset(const char *str, int column); void txt_move_up(struct Text *text, const bool sel); void txt_move_down(struct Text *text, const bool sel); void txt_move_left(struct Text *text, const bool sel); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index b2ea5b12603..562e2814efa 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -703,50 +703,6 @@ bool txt_cursor_is_line_end(Text *text) /* Cursor movement functions */ /*****************************/ -int txt_utf8_offset_to_index(const char *str, int offset) -{ - int index = 0, pos = 0; - while (pos != offset) { - pos += BLI_str_utf8_size(str + pos); - index++; - } - return index; -} - -int txt_utf8_index_to_offset(const char *str, int index) -{ - int offset = 0, pos = 0; - while (pos != index) { - offset += BLI_str_utf8_size(str + offset); - pos++; - } - return offset; -} - -int txt_utf8_offset_to_column(const char *str, int offset) -{ - int column = 0, pos = 0; - while (pos < offset) { - column += BLI_str_utf8_char_width_safe(str + pos); - pos += BLI_str_utf8_size_safe(str + pos); - } - return column; -} - -int txt_utf8_column_to_offset(const char *str, int column) -{ - int offset = 0, pos = 0, col; - while (*(str + offset) && pos < column) { - col = BLI_str_utf8_char_width_safe(str + offset); - if (pos + col > column) { - break; - } - offset += BLI_str_utf8_size_safe(str + offset); - pos += col; - } - return offset; -} - void txt_move_up(Text *text, const bool sel) { TextLine **linep; @@ -764,9 +720,9 @@ void txt_move_up(Text *text, const bool sel) } if ((*linep)->prev) { - int column = txt_utf8_offset_to_column((*linep)->line, *charp); + int column = BLI_str_utf8_offset_to_column((*linep)->line, *charp); *linep = (*linep)->prev; - *charp = txt_utf8_column_to_offset((*linep)->line, column); + *charp = BLI_str_utf8_offset_from_column((*linep)->line, column); } else { txt_move_bol(text, sel); @@ -794,9 +750,9 @@ void txt_move_down(Text *text, const bool sel) } if ((*linep)->next) { - int column = txt_utf8_offset_to_column((*linep)->line, *charp); + int column = BLI_str_utf8_offset_to_column((*linep)->line, *charp); *linep = (*linep)->next; - *charp = txt_utf8_column_to_offset((*linep)->line, column); + *charp = BLI_str_utf8_offset_from_column((*linep)->line, column); } else { txt_move_eol(text, sel); |