1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-02 09:12:08 +02:00

efi_loader: MetaiMatch() must be case insensitive

The MetaiMatch() service of the UnicodeCollationProtocol2 must be case
insensitive.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
Heinrich Schuchardt
2019-06-12 19:18:24 +02:00
parent 0e22c7cbeb
commit 336476a959

View File

@@ -73,11 +73,22 @@ out:
return ret; return ret;
} }
/**
* next_lower() - get next codepoint converted to lower case
*
* @string: pointer to u16 string, on return advanced by one codepoint
* Return: first codepoint of string converted to lower case
*/
static s32 next_lower(const u16 **string)
{
return utf_to_lower(utf16_get(string));
}
/** /**
* metai_match() - compare utf-16 string with a pattern string case-insenitively * metai_match() - compare utf-16 string with a pattern string case-insenitively
* *
* @s: string to compare * @string: string to compare
* @p: pattern string * @pattern: pattern string
* *
* The pattern string may use these: * The pattern string may use these:
* - * matches >= 0 characters * - * matches >= 0 characters
@@ -93,61 +104,67 @@ out:
* *
* Return: true if the string is matched. * Return: true if the string is matched.
*/ */
static bool metai_match(const u16 *s, const u16 *p) static bool metai_match(const u16 *string, const u16 *pattern)
{ {
u16 first; s32 first, s, p;
for (; *s && *p; ++s, ++p) { for (; *string && *pattern;) {
switch (*p) { const u16 *string_old = string;
s = next_lower(&string);
p = next_lower(&pattern);
switch (p) {
case '*': case '*':
/* Match 0 or more characters */ /* Match 0 or more characters */
++p; for (;; s = next_lower(&string)) {
for (;; ++s) { if (metai_match(string_old, pattern))
if (metai_match(s, p))
return true; return true;
if (!*s) if (!s)
return false; return false;
string_old = string;
} }
case '?': case '?':
/* Match any one character */ /* Match any one character */
break; break;
case '[': case '[':
/* Match any character in the set */ /* Match any character in the set */
++p; p = next_lower(&pattern);
first = *p; first = p;
if (first == ']') if (first == ']')
/* Empty set */ /* Empty set */
return false; return false;
++p; p = next_lower(&pattern);
if (*p == '-') { if (p == '-') {
/* Range */ /* Range */
++p; p = next_lower(&pattern);
if (*s < first || *s > *p) if (s < first || s > p)
return false; return false;
++p; p = next_lower(&pattern);
if (*p != ']') if (p != ']')
return false; return false;
} else { } else {
/* Set */ /* Set */
bool hit = false; bool hit = false;
if (*s == first) if (s == first)
hit = true; hit = true;
for (; *p && *p != ']'; ++p) { for (; p && p != ']';
if (*p == *s) p = next_lower(&pattern)) {
if (p == s)
hit = true; hit = true;
} }
if (!hit || *p != ']') if (!hit || p != ']')
return false; return false;
} }
break; break;
default: default:
/* Match one character */ /* Match one character */
if (*p != *s) if (p != s)
return false; return false;
} }
} }
if (!*p && !*s) if (!*pattern && !*string)
return true; return true;
return false; return false;
} }