diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 15 |
2 files changed, 16 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index faa8dc03615..eef4e0647aa 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -85,6 +85,7 @@ size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT void BLI_str_tolower_ascii(char *str, const size_t len) ATTR_NONNULL(); void BLI_str_toupper_ascii(char *str, const size_t len) ATTR_NONNULL(); +void BLI_str_rstrip(char *str) ATTR_NONNULL(); int BLI_str_rstrip_float_zero(char *str, const char pad) ATTR_NONNULL(); int BLI_str_index_in_array_n(const char *__restrict str, const char **__restrict str_array, const int str_array_len) ATTR_NONNULL(); diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index c1696a912ba..f46676ac0cd 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -779,6 +779,21 @@ void BLI_str_toupper_ascii(char *str, const size_t len) } /** + * Strip whitespace from end of the string. + */ +void BLI_str_rstrip(char *str) +{ + for (int i = strlen(str) - 1; i > 0; i--) { + if (isspace(str[i])) { + str[i] = '\0'; + } + else { + break; + } + } +} + +/** * Strip trailing zeros from a float, eg: * 0.0000 -> 0.0 * 2.0010 -> 2.001 |