Browse Source

libobs/util: Fix text-lookup not always case-insensitive

Convert `lookup` to upper-case before creating the tree so that later
code does not need to consider the case-insensitivity.
When converting to upper-case, use `toupper` instead of adding 0x20 so
that the behavior is consistent with `astrcmpi_n`.

(cherry picked from commit 1805712f4695e7ff89ee793f932250283373a9fb)
Norihiro Kamae 2 years ago
parent
commit
375da1a036
1 changed files with 4 additions and 5 deletions
  1. 4 5
      libobs/util/text-lookup.c

+ 4 - 5
libobs/util/text-lookup.c

@@ -14,6 +14,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
  */
 
 
+#include <ctype.h>
 #include "dstr.h"
 #include "dstr.h"
 #include "text-lookup.h"
 #include "text-lookup.h"
 #include "lexer.h"
 #include "lexer.h"
@@ -159,11 +160,6 @@ static void lookup_addstring(const char *lookup_val, struct text_leaf *leaf,
 			char val1 = child->str.array[len],
 			char val1 = child->str.array[len],
 			     val2 = lookup_val[len];
 			     val2 = lookup_val[len];
 
 
-			if (val1 >= 'A' && val1 <= 'Z')
-				val1 += 0x20;
-			if (val2 >= 'A' && val2 <= 'Z')
-				val2 += 0x20;
-
 			if (val1 != val2)
 			if (val1 != val2)
 				break;
 				break;
 		}
 		}
@@ -323,6 +319,9 @@ static void lookup_addfiledata(struct text_lookup *lookup,
 		leaf->lookup = bstrdup_n(name.array, name.len);
 		leaf->lookup = bstrdup_n(name.array, name.len);
 		leaf->value = convert_string(value.array, value.len);
 		leaf->value = convert_string(value.array, value.len);
 
 
+		for (size_t i = 0; i < name.len; i++)
+			leaf->lookup[i] = toupper(leaf->lookup[i]);
+
 		lookup_addstring(leaf->lookup, leaf, lookup->top);
 		lookup_addstring(leaf->lookup, leaf, lookup->top);
 
 
 		if (!lookup_goto_nextline(&lex))
 		if (!lookup_goto_nextline(&lex))