Changeset 28a5ebd in mainline for uspace/lib/fmtutil/fmtutil.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/fmtutil/fmtutil.c

    r4f663f3e r28a5ebd  
    6262
    6363/** Line consumer that prints the lines aligned according to spec */
    64 static errno_t print_line(wchar_t *wstr, size_t chars, bool last, void *data)
     64static errno_t print_line(char32_t *wstr, size_t chars, bool last, void *data)
    6565{
    6666        printmode_t *pm = (printmode_t *) data;
    67         wchar_t old_char = wstr[chars];
     67        char32_t old_char = wstr[chars];
    6868        wstr[chars] = 0;
    6969        errno_t rc = print_aligned_w(wstr, pm->width, last, pm->alignment);
     
    7878        pm.newline_always = false;
    7979        pm.width = width;
    80         wchar_t *wstr = str_to_awstr(str);
     80        char32_t *wstr = str_to_awstr(str);
    8181        if (wstr == NULL) {
    8282                return ENOMEM;
     
    8787}
    8888
    89 errno_t print_aligned_w(const wchar_t *wstr, size_t width, bool last,
     89errno_t print_aligned_w(const char32_t *wstr, size_t width, bool last,
    9090    align_mode_t mode)
    9191{
     
    9595                for (i = 0; i < width; i++) {
    9696                        if (i < len)
    97                                 putwchar(wstr[i]);
     97                                putuchar(wstr[i]);
    9898                        else
    99                                 putwchar(' ');
     99                                putuchar(' ');
    100100                }
    101101        } else if (mode == ALIGN_RIGHT) {
    102102                for (i = 0; i < width; i++) {
    103103                        if (i < width - len)
    104                                 putwchar(' ');
     104                                putuchar(' ');
    105105                        else
    106                                 putwchar(wstr[i - (width - len)]);
     106                                putuchar(wstr[i - (width - len)]);
    107107                }
    108108        } else if (mode == ALIGN_CENTER) {
     
    110110                for (i = 0; i < width; i++) {
    111111                        if ((i < padding) || ((i - padding) >= len))
    112                                 putwchar(' ');
     112                                putuchar(' ');
    113113                        else
    114                                 putwchar(wstr[i - padding]);
     114                                putuchar(wstr[i - padding]);
    115115                }
    116116        } else if (mode == ALIGN_JUSTIFY) {
     
    146146                                    (words - 1)));
    147147                                for (j = 0; j < spaces; j++) {
    148                                         putwchar(' ');
     148                                        putuchar(' ');
    149149                                }
    150150                                done_chars += spaces;
    151151                        }
    152152                        while (i < len && wstr[i] != ' ') {
    153                                 putwchar(wstr[i++]);
     153                                putuchar(wstr[i++]);
    154154                                done_chars++;
    155155                        }
     
    158158        skip_words:
    159159                while (done_chars < width) {
    160                         putwchar(' ');
     160                        putuchar(' ');
    161161                        done_chars++;
    162162                }
     
    169169errno_t print_aligned(const char *str, size_t width, bool last, align_mode_t mode)
    170170{
    171         wchar_t *wstr = str_to_awstr(str);
     171        char32_t *wstr = str_to_awstr(str);
    172172        if (wstr == NULL) {
    173173                return ENOMEM;
     
    178178}
    179179
    180 errno_t wrap(wchar_t *wstr, size_t width, line_consumer_fn consumer, void *data)
     180errno_t wrap(char32_t *wstr, size_t width, line_consumer_fn consumer, void *data)
    181181{
    182182        size_t word_start = 0;
Note: See TracChangeset for help on using the changeset viewer.