Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-09-01 08:24:01 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-09-01 08:24:01 +0300
commit5352b335983279a479abf22abe3a2d3d457597b4 (patch)
tree29eb41397f177bce0090f95185d62ddbc6814d11 /source/blender/blenlib
parent2914ec571e34733ed89a64f182cf4045be49a28f (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')
-rw-r--r--source/blender/blenlib/BLI_string_utils.h8
-rw-r--r--source/blender/blenlib/intern/string_utils.c17
2 files changed, 12 insertions, 13 deletions
diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h
index 1057e71a6b2..277bb6fac05 100644
--- a/source/blender/blenlib/BLI_string_utils.h
+++ b/source/blender/blenlib/BLI_string_utils.h
@@ -75,10 +75,10 @@ char *BLI_string_join_array_by_sep_char_with_tableN(char sep,
BLI_string_join_array_by_sep_char_with_tableN( \
sep, table, ((const char *[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
-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);
bool BLI_uniquename_cb(UniquenameCheckCallback unique_check,
void *arg,
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. */