[Bf-blender-cvs] [ab5f4c4] master: BLI: Add two helpers to search a given string in an array of strings.
Bastien Montagne
noreply at git.blender.org
Tue Jun 17 16:08:43 CEST 2014
Commit: ab5f4c4dfad3880f60c8555437aeb0c9ba85cd1e
Author: Bastien Montagne
Date: Tue Jun 17 15:58:07 2014 +0200
https://developer.blender.org/rBab5f4c4dfad3880f60c8555437aeb0c9ba85cd1e
BLI: Add two helpers to search a given string in an array of strings.
===================================================================
M source/blender/blenlib/BLI_string.h
M source/blender/blenlib/intern/string.c
===================================================================
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index 2cf9047..235147d 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -76,6 +76,9 @@ void BLI_ascii_strtolower(char *str, const size_t len) ATTR_NONNULL();
void BLI_ascii_strtoupper(char *str, const size_t len) 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();
+int BLI_str_index_in_array(const char *__restrict str, const char **__restrict str_array) ATTR_NONNULL();
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index ab81c8f..4ab568e 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -639,3 +639,45 @@ int BLI_str_rstrip_float_zero(char *str, const char pad)
return totstrip;
}
+
+/**
+ * Return index of a string in a string array.
+ *
+ * \param str The string to find.
+ * \param str_array Array of strings.
+ * \param str_array_len The length of the array, or -1 for a NULL-terminated array.
+ * \return The index of str in str_array or -1.
+ */
+int BLI_str_index_in_array_n(const char *str, const char **str_array, const int str_array_len)
+{
+ int index;
+ const char **str_iter = str_array;
+
+ for (index = 0; index < str_array_len; str_iter++, index++) {
+ if (STREQ(str, *str_iter)) {
+ return index;
+ }
+ }
+ return -1;
+}
+
+/**
+ * Return index of a string in a string array.
+ *
+ * \param str The string to find.
+ * \param str_array Array of strings, (must be NULL-terminated).
+ * \return The index of str in str_array or -1.
+ */
+int BLI_str_index_in_array(const char *str, const char **str_array)
+{
+ int index;
+ const char **str_iter = str_array;
+
+ for (index = 0; *str_iter; str_iter++, index++) {
+ if (STREQ(str, *str_iter)) {
+ return index;
+ }
+ }
+ return -1;
+}
+
More information about the Bf-blender-cvs
mailing list