All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 2/5] lib: charset: upper/lower case conversion
Date: Mon,  3 Sep 2018 18:35:38 +0200	[thread overview]
Message-ID: <20180903163541.26218-3-xypron.glpk@gmx.de> (raw)
In-Reply-To: <20180903163541.26218-1-xypron.glpk@gmx.de>

Provide functions for upper and lower case conversion.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v3:
	no change
v2:
	add configuration switch EFI_UNICODE_CAPITALIZATION
---
 include/charset.h      | 16 ++++++++++++++
 lib/charset.c          | 47 ++++++++++++++++++++++++++++++++++++++++++
 lib/efi_loader/Kconfig | 10 +++++++++
 3 files changed, 73 insertions(+)

diff --git a/include/charset.h b/include/charset.h
index 90870513ef..686db5a1fe 100644
--- a/include/charset.h
+++ b/include/charset.h
@@ -142,6 +142,22 @@ int utf16_utf8_strncpy(char **dst, const u16 *src, size_t count);
  */
 #define utf16_utf8_strcpy(d, s) utf16_utf8_strncpy((d), (s), SIZE_MAX)
 
+/**
+ * utf_to_lower() - convert a Unicode letter to lower case
+ *
+ * @code:		letter to convert
+ * Return:		lower case letter or unchanged letter
+ */
+s32 utf_to_lower(const s32 code);
+
+/**
+ * utf_to_upper() - convert a Unicode letter to upper case
+ *
+ * @code:		letter to convert
+ * Return:		upper case letter or unchanged letter
+ */
+s32 utf_to_upper(const s32 code);
+
 /**
  * u16_strlen - count non-zero words
  *
diff --git a/lib/charset.c b/lib/charset.c
index 39c8329830..72c808ce64 100644
--- a/lib/charset.c
+++ b/lib/charset.c
@@ -6,8 +6,18 @@
  */
 
 #include <charset.h>
+#include <capitalization.h>
 #include <malloc.h>
 
+static struct capitalization_table capitalization_table[] =
+#ifdef CONFIG_EFI_UNICODE_CAPITALIZATION
+	UNICODE_CAPITALIZATION_TABLE;
+#elif CONFIG_FAT_DEFAULT_CODEPAGE == 1250
+	CP1250_CAPITALIZATION_TABLE;
+#else
+	CP437_CAPITALIZATION_TABLE;
+#endif
+
 s32 utf8_get(const char **src)
 {
 	s32 code = 0;
@@ -241,6 +251,43 @@ int utf16_utf8_strncpy(char **dst, const u16 *src, size_t count)
 	return 0;
 }
 
+s32 utf_to_lower(const s32 code)
+{
+	struct capitalization_table *pos = capitalization_table;
+	s32 ret = code;
+
+	if (code <= 0x7f) {
+		if (code >= 'A' && code <= 'Z')
+			ret += 0x20;
+		return ret;
+	}
+	for (; pos->upper; ++pos) {
+		if (pos->upper == code) {
+			ret = pos->lower;
+			break;
+		}
+	}
+	return ret;
+}
+
+s32 utf_to_upper(const s32 code)
+{
+	struct capitalization_table *pos = capitalization_table;
+	s32 ret = code;
+
+	if (code <= 0x7f) {
+		if (code >= 'a' && code <= 'z')
+			ret -= 0x20;
+		return ret;
+	}
+	for (; pos->lower; ++pos) {
+		if (pos->lower == code) {
+			ret = pos->upper;
+			break;
+		}
+	}
+	return ret;
+}
 
 size_t u16_strlen(const u16 *in)
 {
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index ce6a09f0b4..dbf7339fe0 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -15,6 +15,16 @@ config EFI_LOADER
 	  interfaces to a loaded EFI application, enabling it to reuse U-Boot's
 	  device drivers.
 
+config EFI_UNICODE_CAPITALIZATION
+	bool "Support Unicode capitalization"
+	depends on EFI_LOADER
+	default y
+	help
+	  Select this option to enable correct handling of the capitalization of
+	  Unicode codepoints in the range 0x0000-0xffff. If this option is not
+	  set, only the the correct handling of the letters of the codepage
+	  used by the FAT file system is ensured.
+
 config EFI_LOADER_BOUNCE_BUFFER
 	bool "EFI Applications use bounce buffers for DMA operations"
 	depends on EFI_LOADER && ARM64
-- 
2.18.0

  parent reply	other threads:[~2018-09-03 16:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03 16:35 [U-Boot] [PATCH v3 00/05]efi_loader: EFI_UNICODE_COLLATION_PROTOCOL Heinrich Schuchardt
2018-09-03 16:35 ` [U-Boot] [PATCH v3 1/5] efi_loader: capitalization table Heinrich Schuchardt
2018-09-03 20:54   ` Alexander Graf
2018-09-03 16:35 ` Heinrich Schuchardt [this message]
2018-09-03 16:35 ` [U-Boot] [PATCH v3 3/5] test: tests for utf_to_lower() utf_to_upper() Heinrich Schuchardt
2018-09-03 16:35 ` [U-Boot] [PATCH v3 4/5] efi_loader: EFI_UNICODE_COLLATION_PROTOCOL Heinrich Schuchardt
2018-09-03 21:09   ` Alexander Graf
2018-09-03 21:24     ` Heinrich Schuchardt
2018-09-03 21:26       ` Alexander Graf
2018-09-04 13:46   ` Alexander Graf
     [not found]     ` <2079463e-a243-3830-eaea-3148af637b42@gmx.de>
2018-09-04 17:20       ` [U-Boot] [Fwd] " Heinrich Schuchardt
2018-09-04 22:04       ` [U-Boot] " Alexander Graf
2018-09-04 22:28         ` Leif Lindholm
2018-09-04 22:35           ` Alexander Graf
2018-09-03 16:35 ` [U-Boot] [PATCH v3 5/5] efi_selftest: EFI_UNICODE_COLLATION_PROTOCOL Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180903163541.26218-3-xypron.glpk@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.