[PATCH v3 4/5] treewide: Use 16-bit unicode strings

Simon Glass sjg at chromium.org
Mon Aug 2 02:56:12 CEST 2021


At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Note: This applies tree-wide

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v3:
- Add a new patch to change non-EFI occurences

 lib/lzma/Types.h  |  4 ++--
 test/print_ut.c   |  2 +-
 test/unicode_ut.c | 22 +++++++++++-----------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/lib/lzma/Types.h b/lib/lzma/Types.h
index 8afcba556eb..04f894a8ca9 100644
--- a/lib/lzma/Types.h
+++ b/lib/lzma/Types.h
@@ -225,9 +225,9 @@ typedef struct
 #else
 
 #define CHAR_PATH_SEPARATOR '/'
-#define WCHAR_PATH_SEPARATOR L'/'
+#define WCHAR_PATH_SEPARATOR u'/'
 #define STRING_PATH_SEPARATOR "/"
-#define WSTRING_PATH_SEPARATOR L"/"
+#define WSTRING_PATH_SEPARATOR u"/"
 
 #endif
 
diff --git a/test/print_ut.c b/test/print_ut.c
index e2bcfbef007..d243650c57c 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -101,7 +101,7 @@ static int print_printf(struct unit_test_state *uts)
 	snprintf(str, 0, "testing none");
 	ut_asserteq('x', *str);
 
-	sprintf(big_str, "_%ls_", L"foo");
+	sprintf(big_str, "_%ls_", u"foo");
 	ut_assertok(strcmp("_foo_", big_str));
 
 	/* Test the banner function */
diff --git a/test/unicode_ut.c b/test/unicode_ut.c
index 617eed8cfa0..f821e5a6be8 100644
--- a/test/unicode_ut.c
+++ b/test/unicode_ut.c
@@ -299,17 +299,17 @@ static int unicode_test_utf8_utf16_strcpy(struct unit_test_state *uts)
 	pos = buf;
 	utf8_utf16_strcpy(&pos, j1);
 	ut_asserteq(4, pos - buf);
-	ut_assert(!unicode_test_u16_strcmp(buf, L"j1?l", SIZE_MAX));
+	ut_assert(!unicode_test_u16_strcmp(buf, u"j1?l", SIZE_MAX));
 
 	pos = buf;
 	utf8_utf16_strcpy(&pos, j2);
 	ut_asserteq(4, pos - buf);
-	ut_assert(!unicode_test_u16_strcmp(buf, L"j2?l", SIZE_MAX));
+	ut_assert(!unicode_test_u16_strcmp(buf, u"j2?l", SIZE_MAX));
 
 	pos = buf;
 	utf8_utf16_strcpy(&pos, j3);
 	ut_asserteq(3, pos - buf);
-	ut_assert(!unicode_test_u16_strcmp(buf, L"j3?", SIZE_MAX));
+	ut_assert(!unicode_test_u16_strcmp(buf, u"j3?", SIZE_MAX));
 
 	return 0;
 }
@@ -584,13 +584,13 @@ UNICODE_TEST(unicode_test_utf_to_upper);
 
 static int unicode_test_u16_strncmp(struct unit_test_state *uts)
 {
-	ut_assert(u16_strncmp(L"abc", L"abc", 3) == 0);
-	ut_assert(u16_strncmp(L"abcdef", L"abcghi", 3) == 0);
-	ut_assert(u16_strncmp(L"abcdef", L"abcghi", 6) < 0);
-	ut_assert(u16_strncmp(L"abcghi", L"abcdef", 6) > 0);
-	ut_assert(u16_strcmp(L"abc", L"abc") == 0);
-	ut_assert(u16_strcmp(L"abcdef", L"deghi") < 0);
-	ut_assert(u16_strcmp(L"deghi", L"abcdef") > 0);
+	ut_assert(u16_strncmp(u"abc", u"abc", 3) == 0);
+	ut_assert(u16_strncmp(u"abcdef", u"abcghi", 3) == 0);
+	ut_assert(u16_strncmp(u"abcdef", u"abcghi", 6) < 0);
+	ut_assert(u16_strncmp(u"abcghi", u"abcdef", 6) > 0);
+	ut_assert(u16_strcmp(u"abc", u"abc") == 0);
+	ut_assert(u16_strcmp(u"abcdef", u"deghi") < 0);
+	ut_assert(u16_strcmp(u"deghi", u"abcdef") > 0);
 	return 0;
 }
 UNICODE_TEST(unicode_test_u16_strncmp);
@@ -713,7 +713,7 @@ UNICODE_TEST(unicode_test_utf8_to_utf32_stream);
 static int unicode_test_efi_create_indexed_name(struct unit_test_state *uts)
 {
 	u16 buf[16];
-	u16 const expected[] = L"Capsule0AF9";
+	u16 const expected[] = u"Capsule0AF9";
 	u16 *pos;
 
 	memset(buf, 0xeb, sizeof(buf));
-- 
2.32.0.554.ge1b32706d8-goog



More information about the U-Boot mailing list