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
  • uspace/lib/c/generic/io/printf_core.c

    r4f663f3e r28a5ebd  
    4747#include <assert.h>
    4848#include <macros.h>
    49 #include <wchar.h>
     49#include <uchar.h>
    5050
    5151/** show prefixes 0x or 0 */
     
    187187 *
    188188 */
    189 static int printf_wputnchars(const wchar_t *buf, size_t size,
     189static int printf_wputnchars(const char32_t *buf, size_t size,
    190190    printf_spec_t *ps)
    191191{
     
    233233 *
    234234 */
    235 static int printf_putwchar(const wchar_t ch, printf_spec_t *ps)
     235static int printf_putuchar(const char32_t ch, printf_spec_t *ps)
    236236{
    237237        if (!chr_check(ch))
    238238                return ps->str_write((void *) &invalch, 1, ps->data);
    239239
    240         return ps->wstr_write(&ch, sizeof(wchar_t), ps->data);
     240        return ps->wstr_write(&ch, sizeof(char32_t), ps->data);
    241241}
    242242
     
    288288 *
    289289 */
    290 static int print_wchar(const wchar_t ch, int width, uint32_t flags, printf_spec_t *ps)
     290static int print_wchar(const char32_t ch, int width, uint32_t flags, printf_spec_t *ps)
    291291{
    292292        size_t counter = 0;
     
    302302        }
    303303
    304         if (printf_putwchar(ch, ps) > 0)
     304        if (printf_putuchar(ch, ps) > 0)
    305305                counter++;
    306306
     
    375375 * @return Number of wide characters printed, negative value on failure.
    376376 */
    377 static int print_wstr(wchar_t *str, int width, unsigned int precision,
     377static int print_wstr(char32_t *str, int width, unsigned int precision,
    378378    uint32_t flags, printf_spec_t *ps)
    379379{
     
    12761276 *  - "l"  Signed or unsigned long int.@n
    12771277 *         If conversion is "c", the character is wint_t (wide character).@n
    1278  *         If conversion is "s", the string is wchar_t * (wide string).@n
     1278 *         If conversion is "s", the string is char32_t * (wide string).@n
    12791279 *  - "ll" Signed or unsigned long long int.@n
    12801280 *  - "z"  Signed or unsigned ssize_t or site_t.@n
     
    13301330        while (true) {
    13311331                i = nxt;
    1332                 wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
     1332                char32_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
    13331333
    13341334                if (uc == 0)
     
    14931493
    14941494                                if (qualifier == PrintfQualifierLong)
    1495                                         retval = print_wstr(va_arg(ap, wchar_t *), width, precision, flags, ps);
     1495                                        retval = print_wstr(va_arg(ap, char32_t *), width, precision, flags, ps);
    14961496                                else
    14971497                                        retval = print_str(va_arg(ap, char *), width, precision, flags, ps);
Note: See TracChangeset for help on using the changeset viewer.