From: Rob Clark <robdclark@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/5] vsprintf.c: add UTF-16 string (%ls) support
Date: Wed, 9 Aug 2017 19:14:33 -0400 [thread overview]
Message-ID: <20170809231441.22691-4-robdclark@gmail.com> (raw)
In-Reply-To: <20170809231441.22691-1-robdclark@gmail.com>
This is convenient for efi_loader which deals a lot with UTF-16. Only
enabled with CC_SHORT_WCHAR, leaving room to add a UTF-32 version when
CC_SHORT_WCHAR is not enabled.
Signed-off-by: Rob Clark <robdclark@gmail.com>
---
examples/api/Makefile | 1 +
lib/vsprintf.c | 31 +++++++++++++++++++++++++++++--
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/examples/api/Makefile b/examples/api/Makefile
index dab6398bab..87c15d0f68 100644
--- a/examples/api/Makefile
+++ b/examples/api/Makefile
@@ -34,6 +34,7 @@ EXT_COBJ-y += lib/div64.o
EXT_COBJ-y += lib/string.o
EXT_COBJ-y += lib/time.o
EXT_COBJ-y += lib/vsprintf.o
+EXT_COBJ-y += lib/charset.o
EXT_SOBJ-$(CONFIG_PPC) += arch/powerpc/lib/ppcstring.o
ifeq ($(ARCH),arm)
EXT_SOBJ-$(CONFIG_USE_ARCH_MEMSET) += arch/arm/lib/memset.o
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 874a2951f7..0678b49b01 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -17,6 +17,7 @@
#include <linux/ctype.h>
#include <common.h>
+#include <charset.h>
#include <div64.h>
#define noinline __attribute__((noinline))
@@ -270,6 +271,26 @@ static char *string(char *buf, char *end, char *s, int field_width,
return buf;
}
+static char *string16(char *buf, char *end, u16 *s, int field_width,
+ int precision, int flags)
+{
+ u16 *str = s ? s : (u16[]){'<','N','U','L','L','>','\0'};
+ int utf16_len = utf16_strnlen(str, precision);
+ u8 utf8[utf16_len * MAX_UTF8_PER_UTF16];
+ int utf8_len, i;
+
+ utf8_len = utf16_to_utf8(utf8, str, utf16_len) - utf8;
+
+ if (!(flags & LEFT))
+ while (utf8_len < field_width--)
+ ADDCH(buf, ' ');
+ for (i = 0; i < utf8_len; ++i)
+ ADDCH(buf, utf8[i]);
+ while (utf8_len < field_width--)
+ ADDCH(buf, ' ');
+ return buf;
+}
+
#ifdef CONFIG_CMD_NET
static const char hex_asc[] = "0123456789abcdef";
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
@@ -528,8 +549,14 @@ repeat:
continue;
case 's':
- str = string(str, end, va_arg(args, char *),
- field_width, precision, flags);
+ if (CONFIG_IS_ENABLED(CC_SHORT_WCHAR) &&
+ qualifier == 'l') {
+ str = string16(str, end, va_arg(args, u16 *),
+ field_width, precision, flags);
+ } else {
+ str = string(str, end, va_arg(args, char *),
+ field_width, precision, flags);
+ }
continue;
case 'p':
--
2.13.0
next prev parent reply other threads:[~2017-08-09 23:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-09 23:14 [U-Boot] [PATCH 0/5] vsprintf and short-wchar for EFI_LOADER Rob Clark
2017-08-09 23:14 ` [U-Boot] [PATCH 1/5] Kconfig: add option to build with -fshort-wchar Rob Clark
2017-08-10 2:28 ` Tom Rini
2017-08-09 23:14 ` [U-Boot] [PATCH 2/5] lib: add some utf16 handling helpers Rob Clark
2017-08-13 21:36 ` Simon Glass
2017-08-09 23:14 ` Rob Clark [this message]
2017-08-13 21:36 ` [U-Boot] [PATCH 3/5] vsprintf.c: add UTF-16 string (%ls) support Simon Glass
2017-08-09 23:14 ` [U-Boot] [PATCH 4/5] vsprintf.c: add GUID printing Rob Clark
2017-08-15 20:12 ` Heinrich Schuchardt
2017-08-09 23:14 ` [U-Boot] [PATCH 5/5] examples: add fallback memcpy Rob Clark
2017-09-06 15:31 ` [U-Boot] [PATCH 0/5] vsprintf and short-wchar for EFI_LOADER Heinrich Schuchardt
2017-09-06 16:45 ` Tom Rini
2017-09-06 18:14 ` Rob Clark
2017-09-06 18:16 ` Tom Rini
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=20170809231441.22691-4-robdclark@gmail.com \
--to=robdclark@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox