Changeset 28a5ebd in mainline for kernel/generic/src/printf


Ignore:
Timestamp:
2020-06-18T15:39:50Z (5 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.

Location:
kernel/generic/src/printf
Files:
3 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);
  • kernel/generic/src/printf/vprintf.c

    r4f663f3e r28a5ebd  
    4747
    4848        while (offset < size) {
    49                 putwchar(str_decode(str, &offset, size));
     49                putuchar(str_decode(str, &offset, size));
    5050                chars++;
    5151        }
     
    5454}
    5555
    56 static int vprintf_wstr_write(const wchar_t *str, size_t size, void *data)
     56static int vprintf_wstr_write(const char32_t *str, size_t size, void *data)
    5757{
    5858        size_t offset = 0;
     
    6060
    6161        while (offset < size) {
    62                 putwchar(str[chars]);
     62                putuchar(str[chars]);
    6363                chars++;
    64                 offset += sizeof(wchar_t);
     64                offset += sizeof(char32_t);
    6565        }
    6666
     
    7272        size_t offset = 0;
    7373        size_t chars = 0;
    74         wchar_t uc;
     74        char32_t uc;
    7575
    7676        while ((uc = str_decode(str, &offset, STR_NO_LIMIT)) != 0) {
    77                 putwchar(uc);
     77                putuchar(uc);
    7878                chars++;
    7979        }
    8080
    81         putwchar('\n');
     81        putuchar('\n');
    8282        return chars;
    8383}
  • kernel/generic/src/printf/vsnprintf.c

    r4f663f3e r28a5ebd  
    8888
    8989                while (index < size) {
    90                         wchar_t uc = str_decode(str, &index, size);
     90                        char32_t uc = str_decode(str, &index, size);
    9191
    9292                        if (chr_encode(uc, data->dst, &data->len, data->size - 1) != EOK)
     
    133133 *
    134134 */
    135 static int vsnprintf_wstr_write(const wchar_t *str, size_t size, vsnprintf_data_t *data)
     135static int vsnprintf_wstr_write(const char32_t *str, size_t size, vsnprintf_data_t *data)
    136136{
    137137        size_t index = 0;
    138138
    139         while (index < (size / sizeof(wchar_t))) {
     139        while (index < (size / sizeof(char32_t))) {
    140140                size_t left = data->size - data->len;
    141141
     
    177177        printf_spec_t ps = {
    178178                (int (*) (const char *, size_t, void *)) vsnprintf_str_write,
    179                 (int (*) (const wchar_t *, size_t, void *)) vsnprintf_wstr_write,
     179                (int (*) (const char32_t *, size_t, void *)) vsnprintf_wstr_write,
    180180                &data
    181181        };
Note: See TracChangeset for help on using the changeset viewer.