efi_loader: carve out utf_to_cp()

Carve out a function to translate a Unicode code point to an 8bit codepage.

Provide a unit test for the new function.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
Heinrich Schuchardt
2021-02-27 14:08:36 +01:00
parent 70616a1ed8
commit 73bb90cabc
4 changed files with 71 additions and 16 deletions

View File

@@ -300,23 +300,10 @@ static bool EFIAPI efi_str_to_fat(struct efi_unicode_collation_protocol *this,
break;
}
c = utf_to_upper(c);
if (c >= 0x80) {
int j;
/* Look for codepage translation */
for (j = 0; j < 0x80; ++j) {
if (c == codepage[j]) {
c = j + 0x80;
break;
}
}
if (j >= 0x80) {
c = '_';
ret = true;
}
} else if (c && (c < 0x20 || strchr(illegal, c))) {
c = '_';
if (utf_to_cp(&c, codepage) ||
(c && (c < 0x20 || strchr(illegal, c)))) {
ret = true;
c = '_';
}
fat[i] = c;