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/srv/hid/input/layout/us_qwerty.c

    r4f663f3e r28a5ebd  
    4343static errno_t us_qwerty_create(layout_t *);
    4444static void us_qwerty_destroy(layout_t *);
    45 static wchar_t us_qwerty_parse_ev(layout_t *, kbd_event_t *ev);
     45static char32_t us_qwerty_parse_ev(layout_t *, kbd_event_t *ev);
    4646
    4747layout_ops_t us_qwerty_ops = {
     
    5151};
    5252
    53 static wchar_t map_lcase[] = {
     53static char32_t map_lcase[] = {
    5454        [KC_Q] = 'q',
    5555        [KC_W] = 'w',
     
    8282};
    8383
    84 static wchar_t map_ucase[] = {
     84static char32_t map_ucase[] = {
    8585        [KC_Q] = 'Q',
    8686        [KC_W] = 'W',
     
    113113};
    114114
    115 static wchar_t map_not_shifted[] = {
     115static char32_t map_not_shifted[] = {
    116116        [KC_BACKTICK] = '`',
    117117
     
    142142};
    143143
    144 static wchar_t map_shifted[] = {
     144static char32_t map_shifted[] = {
    145145        [KC_BACKTICK] = '~',
    146146
     
    171171};
    172172
    173 static wchar_t map_neutral[] = {
     173static char32_t map_neutral[] = {
    174174        [KC_BACKSPACE] = '\b',
    175175        [KC_TAB] = '\t',
     
    184184};
    185185
    186 static wchar_t map_numeric[] = {
     186static char32_t map_numeric[] = {
    187187        [KC_N7] = '7',
    188188        [KC_N8] = '8',
     
    199199};
    200200
    201 static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
     201static char32_t translate(unsigned int key, char32_t *map, size_t map_length)
    202202{
    203203        if (key >= map_length)
     
    215215}
    216216
    217 static wchar_t us_qwerty_parse_ev(layout_t *state, kbd_event_t *ev)
    218 {
    219         wchar_t c;
     217static char32_t us_qwerty_parse_ev(layout_t *state, kbd_event_t *ev)
     218{
     219        char32_t c;
    220220
    221221        /* Produce no characters when Ctrl or Alt is pressed. */
     
    223223                return 0;
    224224
    225         c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
     225        c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char32_t));
    226226        if (c != 0)
    227227                return c;
    228228
    229229        if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
    230                 c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
     230                c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char32_t));
    231231        else
    232                 c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
     232                c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char32_t));
    233233
    234234        if (c != 0)
     
    236236
    237237        if ((ev->mods & KM_SHIFT) != 0)
    238                 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
     238                c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char32_t));
    239239        else
    240                 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
     240                c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char32_t));
    241241
    242242        if (c != 0)
     
    244244
    245245        if ((ev->mods & KM_NUM_LOCK) != 0)
    246                 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
     246                c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char32_t));
    247247        else
    248248                c = 0;
Note: See TracChangeset for help on using the changeset viewer.