Changeset 28a5ebd in mainline for uspace/app/edit


Ignore:
Timestamp:
2020-06-18T15:39:50Z (6 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:
uspace/app/edit
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/edit/edit.c

    r4f663f3e r28a5ebd  
    147147static void pane_caret_display(void);
    148148
    149 static void insert_char(wchar_t c);
     149static void insert_char(char32_t c);
    150150static void delete_char_before(void);
    151151static void delete_char_after(void);
     
    630630        kbd_event_t *kev;
    631631        char *str;
    632         wchar_t buffer[INFNAME_MAX_LEN + 1];
     632        char32_t buffer[INFNAME_MAX_LEN + 1];
    633633        int max_len;
    634634        int nc;
     
    670670                                default:
    671671                                        if (kev->c >= 32 && nc < max_len) {
    672                                                 putwchar(kev->c);
     672                                                putuchar(kev->c);
    673673                                                console_flush(con);
    674674                                                buffer[nc++] = kev->c;
     
    696696{
    697697        FILE *f;
    698         wchar_t c;
     698        char32_t c;
    699699        char buf[BUF_SIZE];
    700700        int bcnt;
     
    850850        coord_t rbc, rec;
    851851        char row_buf[ROW_BUF_SIZE];
    852         wchar_t c;
     852        char32_t c;
    853853        size_t pos, size;
    854854        int s_column;
     
    10551055
    10561056/** Insert a character at caret position. */
    1057 static void insert_char(wchar_t c)
     1057static void insert_char(char32_t c)
    10581058{
    10591059        spt_t pt;
     
    12851285
    12861286/* Search operations */
    1287 static errno_t search_spt_producer(void *data, wchar_t *ret)
     1287static errno_t search_spt_producer(void *data, char32_t *ret)
    12881288{
    12891289        assert(data != NULL);
     
    12941294}
    12951295
    1296 static errno_t search_spt_reverse_producer(void *data, wchar_t *ret)
     1296static errno_t search_spt_reverse_producer(void *data, char32_t *ret)
    12971297{
    12981298        assert(data != NULL);
     
    15131513        char *str;
    15141514        size_t off;
    1515         wchar_t c;
     1515        char32_t c;
    15161516        errno_t rc;
    15171517
     
    16091609}
    16101610
    1611 static wchar_t get_first_wchar(const char *str)
     1611static char32_t get_first_wchar(const char *str)
    16121612{
    16131613        size_t offset = 0;
     
    16301630                return false;
    16311631
    1632         wchar_t first_char = get_first_wchar(ch);
     1632        char32_t first_char = get_first_wchar(ch);
    16331633        switch (first_char) {
    16341634        case ' ':
     
    16561656                return false;
    16571657
    1658         wchar_t first_char = get_first_wchar(ch);
     1658        char32_t first_char = get_first_wchar(ch);
    16591659        switch (first_char) {
    16601660        case ',':
  • uspace/app/edit/search.c

    r4f663f3e r28a5ebd  
    5050                return NULL;
    5151
    52         wchar_t *p = str_to_awstr(pattern);
     52        char32_t *p = str_to_awstr(pattern);
    5353        if (p == NULL) {
    5454                free(search);
     
    6363                half = search->pattern_length / 2;
    6464                for (pos = 0; pos < half; pos++) {
    65                         wchar_t tmp = p[pos];
     65                        char32_t tmp = p[pos];
    6666                        p[pos] = p[search->pattern_length - pos - 1];
    6767                        p[search->pattern_length - pos - 1] = tmp;
     
    107107        search_equals_fn eq = s->ops.equals;
    108108
    109         wchar_t cur_char;
     109        char32_t cur_char;
    110110        errno_t rc = EOK;
    111111        while ((rc = s->ops.producer(s->client_data, &cur_char)) == EOK && cur_char > 0) {
     
    141141}
    142142
    143 bool char_exact_equals(const wchar_t a, const wchar_t b)
     143bool char_exact_equals(const char32_t a, const char32_t b)
    144144{
    145145        return a == b;
  • uspace/app/edit/search.h

    r4f663f3e r28a5ebd  
    4242struct search;
    4343typedef struct search search_t;
    44 typedef bool (*search_equals_fn)(const wchar_t, const wchar_t);
    45 typedef errno_t (*search_producer_fn)(void *, wchar_t *);
     44typedef bool (*search_equals_fn)(const char32_t, const char32_t);
     45typedef errno_t (*search_producer_fn)(void *, char32_t *);
    4646typedef errno_t (*search_mark_fn)(void *, void **);
    4747typedef void (*search_mark_free_fn)(void *);
     
    5959} search_ops_t;
    6060
    61 extern bool char_exact_equals(const wchar_t, const wchar_t);
     61extern bool char_exact_equals(const char32_t, const char32_t);
    6262extern search_t *search_init(const char *, void *, search_ops_t, bool);
    6363extern errno_t search_next_match(search_t *, match_t *);
  • uspace/app/edit/search_impl.h

    r4f663f3e r28a5ebd  
    4343        /* Note: This structure is opaque for the user. */
    4444
    45         wchar_t *pattern;
     45        char32_t *pattern;
    4646        size_t pattern_length;
    4747        ssize_t *back_table;
  • uspace/app/edit/sheet.c

    r4f663f3e r28a5ebd  
    195195        size_t copy_sz;
    196196        size_t off, prev;
    197         wchar_t c;
     197        char32_t c;
    198198
    199199        spp = sh->data + spos->b_off;
     
    222222{
    223223        size_t cur_pos, prev_pos;
    224         wchar_t c;
     224        char32_t c;
    225225        coord_t cc;
    226226
     
    291291        size_t off;
    292292        coord_t cc;
    293         wchar_t c;
     293        char32_t c;
    294294        sheet_t *sh;
    295295
     
    320320
    321321/** Get a character at spt and return next spt */
    322 wchar_t spt_next_char(spt_t spt, spt_t *next)
    323 {
    324         wchar_t ch = str_decode(spt.sh->data, &spt.b_off, spt.sh->text_size);
     322char32_t spt_next_char(spt_t spt, spt_t *next)
     323{
     324        char32_t ch = str_decode(spt.sh->data, &spt.b_off, spt.sh->text_size);
    325325        if (next)
    326326                *next = spt;
     
    328328}
    329329
    330 wchar_t spt_prev_char(spt_t spt, spt_t *prev)
    331 {
    332         wchar_t ch = str_decode_reverse(spt.sh->data, &spt.b_off, spt.sh->text_size);
     330char32_t spt_prev_char(spt_t spt, spt_t *prev)
     331{
     332        char32_t ch = str_decode_reverse(spt.sh->data, &spt.b_off, spt.sh->text_size);
    333333        if (prev)
    334334                *prev = spt;
  • uspace/app/edit/sheet.h

    r4f663f3e r28a5ebd  
    101101extern void spt_get_coord(spt_t const *, coord_t *);
    102102extern bool spt_equal(spt_t const *, spt_t const *);
    103 extern wchar_t spt_next_char(spt_t, spt_t *);
    104 extern wchar_t spt_prev_char(spt_t, spt_t *);
     103extern char32_t spt_next_char(spt_t, spt_t *);
     104extern char32_t spt_prev_char(spt_t, spt_t *);
    105105
    106106extern void sheet_place_tag(sheet_t *, spt_t const *, tag_t *);
Note: See TracChangeset for help on using the changeset viewer.