mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2025-05-28 22:45:15 +02:00
stdio: support for UTF-8 %lc in printf()
This commit is contained in:
parent
e8779145c2
commit
89c6c39405
3 changed files with 29 additions and 9 deletions
|
@ -85,12 +85,8 @@ struct __printf_format {
|
||||||
int16_t precision;
|
int16_t precision;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Size specifier for integers (%o, %x, %i, %d, %u), may be one of:
|
** Size specifier for integers (%o, %x, %i, %d, %u), is equal to the
|
||||||
** (0) char (8-bit)
|
** sizeof() of the targeted type. Also used for %lc.
|
||||||
** (1) short (16-bit)
|
|
||||||
** (2) int (32-bit)
|
|
||||||
** (3) long (32-bit)
|
|
||||||
** (4) long long (64-bit)
|
|
||||||
*/
|
*/
|
||||||
uint8_t size;
|
uint8_t size;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,27 @@ void __printf_format_c(
|
||||||
__printf_compute_geometry(opt, &g);
|
__printf_compute_geometry(opt, &g);
|
||||||
|
|
||||||
__printf_outn(out, ' ', g.left_spaces);
|
__printf_outn(out, ' ', g.left_spaces);
|
||||||
__printf_out(out, c);
|
|
||||||
|
/* When using %lc, output as UTF-8 */
|
||||||
|
if(opt->size != 4 || c <= 0x7f) {
|
||||||
|
__printf_out(out, c);
|
||||||
|
}
|
||||||
|
else if(c <= 0x7ff) {
|
||||||
|
__printf_out(out, 0xc0 | (c >> 6));
|
||||||
|
__printf_out(out, 0x80 | (c & 0x3f));
|
||||||
|
}
|
||||||
|
else if(c <= 0xffff) {
|
||||||
|
__printf_out(out, 0xe0 | (c >> 12));
|
||||||
|
__printf_out(out, 0x80 | ((c >> 6) & 0x3f));
|
||||||
|
__printf_out(out, 0x80 | (c & 0x3f));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
__printf_out(out, 0xf0 | (c >> 18));
|
||||||
|
__printf_out(out, 0x80 | ((c >> 12) & 0x3f));
|
||||||
|
__printf_out(out, 0x80 | ((c >> 6) & 0x3f));
|
||||||
|
__printf_out(out, 0x80 | (c & 0x3f));
|
||||||
|
}
|
||||||
|
|
||||||
__printf_outn(out, ' ', g.right_spaces);
|
__printf_outn(out, ' ', g.right_spaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,8 +125,8 @@ void __printf_flush(struct __printf_output *out)
|
||||||
/* Parse format strings. */
|
/* Parse format strings. */
|
||||||
static struct __printf_format parse_fmt(char const * restrict *options_ptr)
|
static struct __printf_format parse_fmt(char const * restrict *options_ptr)
|
||||||
{
|
{
|
||||||
/* No options enabled by default, set the size to int */
|
/* No options enabled by default; default size is set at the end */
|
||||||
struct __printf_format opt = { .size = sizeof(int), .precision = -1 };
|
struct __printf_format opt = { .size = 0, .precision = -1 };
|
||||||
|
|
||||||
/* This function acts as a deterministic finite automaton */
|
/* This function acts as a deterministic finite automaton */
|
||||||
enum {
|
enum {
|
||||||
|
@ -252,6 +252,10 @@ int __printf(
|
||||||
opt = parse_fmt(&format);
|
opt = parse_fmt(&format);
|
||||||
opt.spec = *format++;
|
opt.spec = *format++;
|
||||||
|
|
||||||
|
/* Set default size to 1 for %c, 4 otherwise */
|
||||||
|
if(opt.size == 0)
|
||||||
|
opt.size = (opt.spec == 'c') ? 1 : 4;
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
if(isupper(opt.spec))
|
if(isupper(opt.spec))
|
||||||
id = opt.spec - 'A';
|
id = opt.spec - 'A';
|
||||||
|
|
Loading…
Add table
Reference in a new issue