diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-27 06:47:39 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-27 06:47:39 +0400 |
commit | d6d8de015c0cc70b8f0e2bbdf3cbd39e6176e31e (patch) | |
tree | c900584ced35ff3187d5bec75b365de58e723956 | |
parent | e903701450fd1ffe4d793a60e3c174ee47fe66dd (diff) |
change BLI_strlen_range_utf8 to the more conventional BLI_strnlen_utf8
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_string_utf8.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string_utf8.c | 14 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 2 |
5 files changed, 15 insertions, 7 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 943597b6688..ba906e1221c 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -204,7 +204,7 @@ __attribute__((warn_unused_result)) __attribute__((nonnull)) #endif ; -size_t BLI_strnlen(const char *str, size_t maxlen) +size_t BLI_strnlen(const char *str, const size_t maxlen) #ifdef __GNUC__ __attribute__((warn_unused_result)) __attribute__((nonnull)) diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 20b56f85b53..73f138a750d 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -50,7 +50,7 @@ char *BLI_str_prev_char_utf8(const char *p); /* wchar_t functions, copied from blenders own font.c originally */ size_t BLI_wstrlen_utf8(const wchar_t *src); size_t BLI_strlen_utf8(const char *strc); -size_t BLI_strlen_range_utf8(const char *start, const char *end); +size_t BLI_strnlen_utf8(const char *start, const size_t maxlen); size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxcpy); size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, const size_t maxcpy); diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 40b2fc20cfa..73d88ddd259 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -416,7 +416,7 @@ void BLI_timestr(double _time, char *str) } /* determine the length of a fixed-size string */ -size_t BLI_strnlen(const char *str, size_t maxlen) +size_t BLI_strnlen(const char *str, const size_t maxlen) { const char *end = memchr(str, '\0', maxlen); return end ? (size_t) (end - str) : maxlen; diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index 7f6057dfdc4..5684b12cc8b 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -261,13 +261,21 @@ size_t BLI_strlen_utf8(const char *strc) return len; } -size_t BLI_strlen_range_utf8(const char *start, const char *end) +/** + * \param start the string to measure the length. + * \param maxlen the string length (in bytes) + * \return the unicode length (not in bytes!) + */ +size_t BLI_strnlen_utf8(const char *start, const size_t maxlen) { const char *strc = start; - int len; + const char *strc_end = start + maxlen; - for (len = 0; strc < end; len++) + size_t len; + + for (len = 0; *strc && strc < strc_end; len++) { strc += strlen_utf8_char(strc); + } return len; } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index c903fd4186e..0b66c5564c6 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1324,7 +1324,7 @@ static int ui_text_position_from_hidden(uiBut *but, int pos) static int ui_text_position_to_hidden(uiBut *but, int pos) { - return BLI_strlen_range_utf8(but->drawstr, but->drawstr + pos); + return BLI_strnlen_utf8(but->drawstr, pos); } void ui_button_text_password_hide(char password_str[UI_MAX_DRAW_STR], uiBut *but, int restore) |