diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-09-01 08:24:01 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-09-01 08:24:01 +0300 |
commit | 5352b335983279a479abf22abe3a2d3d457597b4 (patch) | |
tree | 29eb41397f177bce0090f95185d62ddbc6814d11 /source/blender/blenlib/intern/string_utils.c | |
parent | 2914ec571e34733ed89a64f182cf4045be49a28f (diff) |
BLI_string: return string length from BLI_string_flip_side_name
Useful for callers that need the string length.
Diffstat (limited to 'source/blender/blenlib/intern/string_utils.c')
-rw-r--r-- | source/blender/blenlib/intern/string_utils.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/source/blender/blenlib/intern/string_utils.c b/source/blender/blenlib/intern/string_utils.c index d2666c6fe63..bd733aca4f1 100644 --- a/source/blender/blenlib/intern/string_utils.c +++ b/source/blender/blenlib/intern/string_utils.c @@ -155,11 +155,12 @@ void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, cons * \param from_name: original name, * assumed to be a pointer to a string of at least \a name_len size. * \param strip_number: If set, remove number extensions. + * \return The number of bytes written into \a r_name. */ -void BLI_string_flip_side_name(char *r_name, - const char *from_name, - const bool strip_number, - const size_t name_len) +size_t BLI_string_flip_side_name(char *r_name, + const char *from_name, + const bool strip_number, + const size_t name_len) { size_t len; char *prefix = alloca(name_len); /* The part before the facing */ @@ -172,12 +173,10 @@ void BLI_string_flip_side_name(char *r_name, *prefix = *suffix = *replace = *number = '\0'; /* always copy the name, since this can be called with an uninitialized string */ - BLI_strncpy(r_name, from_name, name_len); - - len = BLI_strnlen(from_name, name_len); + len = BLI_strncpy_rlen(r_name, from_name, name_len); if (len < 3) { /* we don't do names like .R or .L */ - return; + return len; } /* We first check the case with a .### extension, let's find the last period */ @@ -274,7 +273,7 @@ void BLI_string_flip_side_name(char *r_name, } } - BLI_snprintf(r_name, name_len, "%s%s%s%s", prefix, replace, suffix, number); + return BLI_snprintf_rlen(r_name, name_len, "%s%s%s%s", prefix, replace, suffix, number); } /* Unique name utils. */ |