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-04-21 10:43:51 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-04-21 10:43:51 +0300
commitf9867c1f119a1e3430b867ca0a51ec63c6e0d29f (patch)
treeb372b47e42e21d3884e045fd9286384797a248c9
parent3003fbbecfc1084a89282883a676702e087452f5 (diff)
parent06c682423a4374536c081a2b5c77446b5aa04d1e (diff)
Merge branch 'blender-v2.93-release'
-rw-r--r--source/blender/blenlib/BLI_string.h5
-rw-r--r--source/blender/blenlib/intern/string.c23
2 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index 096e7818013..5a80680c350 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -68,6 +68,11 @@ char *BLI_str_replaceN(const char *__restrict str,
void BLI_str_replace_char(char *string, char src, char dst) ATTR_NONNULL();
+bool BLI_str_replace_table_exact(char *string,
+ const size_t string_len,
+ const char *replace_table[][2],
+ int replace_table_len);
+
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...)
ATTR_NONNULL(1, 3) ATTR_PRINTF_FORMAT(3, 4);
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...)
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index ccc11af9f2b..3d40c6ef146 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -540,6 +540,29 @@ void BLI_str_replace_char(char *str, char src, char dst)
}
/**
+ * Simple exact-match string replacement.
+ *
+ * \param replace_table: Array of source, destination pairs.
+ *
+ * \note Larger tables should use a hash table.
+ */
+bool BLI_str_replace_table_exact(char *string,
+ const size_t string_len,
+ const char *replace_table[][2],
+ int replace_table_len)
+{
+ for (int i = 0; i < replace_table_len; i++) {
+ if (STREQ(string, replace_table[i][0])) {
+ BLI_strncpy(string, replace_table[i][1], string_len);
+ return true;
+ }
+ }
+ return false;
+}
+
+/** \} */
+
+/**
* Compare two strings without regard to case.
*
* \retval True if the strings are equal, false otherwise.