Changeset 28a5ebd in mainline for uspace/lib/clui/tinput.c


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/clui/tinput.c

    r4f663f3e r28a5ebd  
    113113static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad)
    114114{
    115         wchar_t *dbuf = malloc((INPUT_MAX_SIZE + 1) * sizeof(wchar_t));
     115        char32_t *dbuf = malloc((INPUT_MAX_SIZE + 1) * sizeof(char32_t));
    116116        if (!dbuf)
    117117                return;
     
    126126        size_t p = start;
    127127        if (p < sa) {
    128                 memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(wchar_t));
     128                memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(char32_t));
    129129                dbuf[sa - p] = '\0';
    130130                printf("%ls", dbuf);
     
    137137
    138138                memcpy(dbuf, ti->buffer + p,
    139                     (sb - p) * sizeof(wchar_t));
     139                    (sb - p) * sizeof(char32_t));
    140140                dbuf[sb - p] = '\0';
    141141                printf("%ls", dbuf);
     
    148148        if (p < ti->nc) {
    149149                memcpy(dbuf, ti->buffer + p,
    150                     (ti->nc - p) * sizeof(wchar_t));
     150                    (ti->nc - p) * sizeof(char32_t));
    151151                dbuf[ti->nc - p] = '\0';
    152152                printf("%ls", dbuf);
     
    154154
    155155        for (p = 0; p < pad; p++)
    156                 putwchar(' ');
     156                putuchar(' ');
    157157
    158158        console_flush(ti->console);
     
    192192        tinput_console_set_lpos(ti, ti->text_coord + ti->nc);
    193193        console_flush(ti->console);
    194         putwchar('\n');
     194        putuchar('\n');
    195195}
    196196
     
    212212}
    213213
    214 static void tinput_insert_char(tinput_t *ti, wchar_t c)
     214static void tinput_insert_char(tinput_t *ti, char32_t c)
    215215{
    216216        if (ti->nc == INPUT_MAX_SIZE)
     
    263263        size_t i = 0;
    264264        while (i < ilen) {
    265                 wchar_t c = str_decode(str, &off, STR_NO_LIMIT);
     265                char32_t c = str_decode(str, &off, STR_NO_LIMIT);
    266266                if (c == '\0')
    267267                        break;
     
    506506
    507507        memmove(ti->buffer + sa, ti->buffer + sb,
    508             (ti->nc - sb) * sizeof(wchar_t));
     508            (ti->nc - sb) * sizeof(char32_t));
    509509
    510510        ti->pos = ti->sel_start = sa;
     
    526526
    527527        if (sb < ti->nc) {
    528                 wchar_t tmp_c = ti->buffer[sb];
     528                char32_t tmp_c = ti->buffer[sb];
    529529                ti->buffer[sb] = '\0';
    530530                str = wstr_to_astr(ti->buffer + sa);
     
    602602        size_t i;
    603603        size_t a_off, b_off;
    604         wchar_t ca, cb;
     604        char32_t ca, cb;
    605605
    606606        i = 0;
Note: See TracChangeset for help on using the changeset viewer.