[Bf-blender-cvs] [5352b335983] master: BLI_string: return string length from BLI_string_flip_side_name

Campbell Barton noreply at git.blender.org
Wed Sep 1 07:33:44 CEST 2021


Commit: 5352b335983279a479abf22abe3a2d3d457597b4
Author: Campbell Barton
Date:   Wed Sep 1 15:24:01 2021 +1000
Branches: master
https://developer.blender.org/rB5352b335983279a479abf22abe3a2d3d457597b4

BLI_string: return string length from BLI_string_flip_side_name

Useful for callers that need the string length.

===================================================================

M	source/blender/blenlib/BLI_string_utils.h
M	source/blender/blenlib/intern/string_utils.c

===================================================================

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. */



More information about the Bf-blender-cvs mailing list