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:
authorPhilipp Oeser <info@graphics-engineer.com>2020-07-07 11:08:42 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2020-09-04 11:11:45 +0300
commit2a24b3aaf4c846a5d98f783fef69946584865df9 (patch)
tree34b33b8512d0bc821f5ada704c37a868046869f1 /source/blender/blenlib/intern/string.c
parent92b8d7019b4b484dc3120b26a27a59a3c7dc5489 (diff)
Fix T78084: Search does not accept text fragments everywhere
This was reported for the "Add Node" search functionality, but is relevant in other searches as well. So e.g. when searching for "Separate XYZ", typing "sep", then " " (with the intention to type "X" next) would clear the search field. Now use the same method (matching against all search words) as in F3 searching ('menu_search_update_fn') in other searches as well [searching IDs, property objects, finding nodes,...] This should give a much nicer search experience in general. Note: this does not touch other searches in the Dopesheet, Outliner, Filebrowser or User Preferences that have other search implementations. Maniphest Tasks: T78084 Differential Revision: https://developer.blender.org/D8232
Diffstat (limited to 'source/blender/blenlib/intern/string.c')
-rw-r--r--source/blender/blenlib/intern/string.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 755637ac274..02d12d2df9b 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -524,6 +524,39 @@ char *BLI_strcasestr(const char *s, const char *find)
return ((char *)s);
}
+int BLI_string_max_possible_word_count(const int str_len)
+{
+ return (str_len / 2) + 1;
+}
+
+bool BLI_string_has_word_prefix(const char *haystack, const char *needle, size_t needle_len)
+{
+ const char *match = BLI_strncasestr(haystack, needle, needle_len);
+ if (match) {
+ if ((match == haystack) || (*(match - 1) == ' ') || ispunct(*(match - 1))) {
+ return true;
+ }
+ return BLI_string_has_word_prefix(match + 1, needle, needle_len);
+ }
+ return false;
+}
+
+bool BLI_string_all_words_matched(const char *name,
+ const char *str,
+ int (*words)[2],
+ const int words_len)
+{
+ int index;
+ for (index = 0; index < words_len; index++) {
+ if (!BLI_string_has_word_prefix(name, str + words[index][0], (size_t)words[index][1])) {
+ break;
+ }
+ }
+ const bool all_words_matched = (index == words_len);
+
+ return all_words_matched;
+}
+
/**
* Variation of #BLI_strcasestr with string length limited to \a len
*/