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>2016-03-23 10:45:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-03-23 10:51:29 +0300
commit80a7efdc1d395f44a14e7bf1085a5d1b3fe45547 (patch)
tree7c7dc860c64ee1ad933350e67c80d9a36a970637 /source/blender/blenlib/intern/string.c
parentb0a7e77700535a0fb021505f1920322d633926d4 (diff)
UI: multi word filtering in search menu
D1080 by @rockets, with own improvements to tests
Diffstat (limited to 'source/blender/blenlib/intern/string.c')
-rw-r--r--source/blender/blenlib/intern/string.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index aad4649344f..2f67b0e57a3 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -525,6 +525,26 @@ char *BLI_strcasestr(const char *s, const char *find)
return ((char *) s);
}
+/**
+ * Variation of #BLI_strcasestr with string length limited to \a len
+ */
+char *BLI_strncasestr(const char *s, const char *find, size_t len)
+{
+ register char c, sc;
+
+ if ((c = *find++) != 0) {
+ c = tolower(c);
+ do {
+ do {
+ if ((sc = *s++) == 0)
+ return (NULL);
+ sc = tolower(sc);
+ } while (sc != c);
+ } while (BLI_strncasecmp(s, find, len - 1) != 0);
+ s--;
+ }
+ return ((char *)s);
+}
int BLI_strcasecmp(const char *s1, const char *s2)
{
@@ -962,3 +982,49 @@ size_t BLI_str_format_int_grouped(char dst[16], int num)
return (size_t)(p_dst - dst);
}
+
+/**
+ * Find the ranges needed to split \a str into its individual words.
+ *
+ * \param str: The string to search for words.
+ * \param len: Size of the string to search.
+ * \param delim: Character to use as a delimiter.
+ * \param r_words: Info about the words found. Set to [index, len] pairs.
+ * \param words_max: Max number of words to find
+ * \return The number of words found in \a str
+ */
+int BLI_string_find_split_words(
+ const char *str, const size_t len,
+ const char delim, int r_words[][2], int words_max)
+{
+ int n = 0, i;
+ bool charsearch = true;
+
+ /* Skip leading spaces */
+ for (i = 0; (i < len) && (str[i] != '\0'); i++) {
+ if (str[i] != delim) {
+ break;
+ }
+ }
+
+ for (; (i < len) && (str[i] != '\0') && (n < words_max); i++) {
+ if ((str[i] != delim) && (charsearch == true)) {
+ r_words[n][0] = i;
+ charsearch = false;
+ }
+ else {
+ if ((str[i] == delim) && (charsearch == false)) {
+ r_words[n][1] = i - r_words[n][0];
+ n++;
+ charsearch = true;
+ }
+ }
+ }
+
+ if (charsearch == false) {
+ r_words[n][1] = i - r_words[n][0];
+ n++;
+ }
+
+ return n;
+}