diff options
author | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-10 16:18:12 +0300 |
---|---|---|
committer | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-10 16:18:12 +0300 |
commit | 67474a7e622957044bc708119a7cfa49a82790fd (patch) | |
tree | 1689263da79f08b1c3c9725ac56c3da8b5d91fbb /source/blender/blenlib/intern/string_utf8.c | |
parent | b091542fe91353c15dd7240ba7ce8ecf72d4011b (diff) | |
parent | 553b581f25c1782c4231816965cd3f6ce58a449a (diff) |
Merge master to soc-2019-cycles-procedural.soc-2019-cycles-procedural
Diffstat (limited to 'source/blender/blenlib/intern/string_utf8.c')
-rw-r--r-- | source/blender/blenlib/intern/string_utf8.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index 01412416854..22c23727d76 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -868,3 +868,53 @@ size_t BLI_str_partition_ex_utf8(const char *str, *suf = *sep = NULL; return str_len; } + +/* -------------------------------------------------------------------- */ +/** \name Offset Conversion in Strings + * \{ */ + +int BLI_str_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 BLI_str_utf8_offset_from_index(const char *str, int index) +{ + int offset = 0, pos = 0; + while (pos != index) { + offset += BLI_str_utf8_size(str + offset); + pos++; + } + return offset; +} + +int BLI_str_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 BLI_str_utf8_offset_from_column(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; +} + +/** \} */ |