Changes in boot/generic/src/str.c [28a5ebd:d066259] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • boot/generic/src/str.c

    r28a5ebd rd066259  
    3838 * strings, called just strings are encoded in UTF-8. Wide strings (encoded
    3939 * in UTF-32) are supported to a limited degree. A single character is
    40  * represented as char32_t.@n
     40 * represented as wchar_t.@n
    4141 *
    4242 * Overview of the terminology:@n
     
    4646 *  byte                  8 bits stored in uint8_t (unsigned 8 bit integer)
    4747 *
    48  *  character             UTF-32 encoded Unicode character, stored in char32_t
    49  *                        (unsigned 32 bit integer), code points 0 .. 1114111
     48 *  character             UTF-32 encoded Unicode character, stored in wchar_t
     49 *                        (signed 32 bit integer), code points 0 .. 1114111
    5050 *                        are valid
    5151 *
     
    5757 *
    5858 *  wide string           UTF-32 encoded NULL-terminated Unicode string,
    59  *                        char32_t *
     59 *                        wchar_t *
    6060 *
    6161 *  [wide] string size    number of BYTES in a [wide] string (excluding
     
    9696 * A specific character inside a [wide] string can be referred to by:@n
    9797 *
    98  *  pointer (char *, char32_t *)
     98 *  pointer (char *, wchar_t *)
    9999 *  byte offset (size_t)
    100100 *  character index (size_t)
     
    109109#include <stdint.h>
    110110
     111/** Check the condition if wchar_t is signed */
     112#ifdef __WCHAR_UNSIGNED__
     113#define WCHAR_SIGNED_CHECK(cond)  (true)
     114#else
     115#define WCHAR_SIGNED_CHECK(cond)  (cond)
     116#endif
     117
    111118/** Byte mask consisting of lowest @n bits (out of 8) */
    112119#define LO_MASK_8(n)  ((uint8_t) ((1 << (n)) - 1))
     
    136143 *
    137144 */
    138 char32_t str_decode(const char *str, size_t *offset, size_t size)
     145wchar_t str_decode(const char *str, size_t *offset, size_t size)
    139146{
    140147        if (*offset + 1 > size)
     
    173180                return U_SPECIAL;
    174181
    175         char32_t ch = b0 & LO_MASK_8(b0_bits);
     182        wchar_t ch = b0 & LO_MASK_8(b0_bits);
    176183
    177184        /* Decode continuation bytes */
     
    184191
    185192                /* Shift data bits to ch */
    186                 ch = (ch << CONT_BITS) | (char32_t) (b & LO_MASK_8(CONT_BITS));
     193                ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS));
    187194                cbytes--;
    188195        }
     
    206213 *         code was invalid.
    207214 */
    208 errno_t chr_encode(const char32_t ch, char *str, size_t *offset, size_t size)
     215errno_t chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
    209216{
    210217        if (*offset >= size)
     
    333340 *
    334341 */
    335 bool ascii_check(char32_t ch)
    336 {
    337         if (ch <= 127)
     342bool ascii_check(wchar_t ch)
     343{
     344        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    338345                return true;
    339346
     
    346353 *
    347354 */
    348 bool chr_check(char32_t ch)
    349 {
    350         if (ch <= 1114111)
     355bool chr_check(wchar_t ch)
     356{
     357        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    351358                return true;
    352359
     
    374381int str_cmp(const char *s1, const char *s2)
    375382{
    376         char32_t c1 = 0;
    377         char32_t c2 = 0;
     383        wchar_t c1 = 0;
     384        wchar_t c2 = 0;
    378385
    379386        size_t off1 = 0;
     
    414421        size_t dest_off = 0;
    415422
    416         char32_t ch;
     423        wchar_t ch;
    417424        while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
    418425                if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
Note: See TracChangeset for help on using the changeset viewer.