Ignore:
Timestamp:
2020-06-18T15:39:50Z (4 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce52c333
Parents:
4f663f3e
Message:

Use char32_t instead of wchat_t to represent UTF-32 strings

The intention of the native HelenOS string API has been always to
support Unicode in the UTF-8 and UTF-32 encodings as the sole character
representations and ignore the obsolete mess of older single-byte and
multibyte character encodings. Before C11, the wchar_t type has been
slightly misused for the purpose of the UTF-32 strings. The newer
char32_t type is obviously a much more suitable option. The standard
defines char32_t as uint_least32_t, thus we can take the liberty to fix
it to uint32_t.

To maintain compatilibity with the C Standard, the putwchar(wchar_t)
functions has been replaced by our custom putuchar(char32_t) functions
where appropriate.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/printf/printf_core.c

    r4f663f3e r28a5ebd  
    139139 *
    140140 */
    141 static int printf_wputnchars(const wchar_t *buf, size_t size,
     141static int printf_wputnchars(const char32_t *buf, size_t size,
    142142    printf_spec_t *ps)
    143143{
     
    185185 *
    186186 */
    187 static int printf_putwchar(const wchar_t ch, printf_spec_t *ps)
     187static int printf_putuchar(const char32_t ch, printf_spec_t *ps)
    188188{
    189189        if (!chr_check(ch))
    190190                return ps->str_write((void *) &invalch, 1, ps->data);
    191191
    192         return ps->wstr_write(&ch, sizeof(wchar_t), ps->data);
     192        return ps->wstr_write(&ch, sizeof(char32_t), ps->data);
    193193}
    194194
     
    240240 *
    241241 */
    242 static int print_wchar(const wchar_t ch, int width, uint32_t flags, printf_spec_t *ps)
     242static int print_wchar(const char32_t ch, int width, uint32_t flags, printf_spec_t *ps)
    243243{
    244244        size_t counter = 0;
     
    254254        }
    255255
    256         if (printf_putwchar(ch, ps) > 0)
     256        if (printf_putuchar(ch, ps) > 0)
    257257                counter++;
    258258
     
    326326 * @return Number of wide characters printed, negative value on failure.
    327327 */
    328 static int print_wstr(wchar_t *str, int width, unsigned int precision,
     328static int print_wstr(char32_t *str, int width, unsigned int precision,
    329329    uint32_t flags, printf_spec_t *ps)
    330330{
     
    576576 *  - "l"  Signed or unsigned long int.@n
    577577 *         If conversion is "c", the character is wint_t (wide character).@n
    578  *         If conversion is "s", the string is wchar_t * (wide string).@n
     578 *         If conversion is "s", the string is char32_t * (UTF-32 string).@n
    579579 *  - "ll" Signed or unsigned long long int.@n
    580580 *  - "z"  Signed or unsigned ssize_t or site_t.@n
     
    630630        while (true) {
    631631                i = nxt;
    632                 wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
     632                char32_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
    633633
    634634                if (uc == 0)
     
    789789                        case 's':
    790790                                if (qualifier == PrintfQualifierLong)
    791                                         retval = print_wstr(va_arg(ap, wchar_t *), width, precision, flags, ps);
     791                                        retval = print_wstr(va_arg(ap, char32_t *), width, precision, flags, ps);
    792792                                else
    793793                                        retval = print_str(va_arg(ap, char *), width, precision, flags, ps);
Note: See TracChangeset for help on using the changeset viewer.