Changeset 28a5ebd in mainline for boot/generic/src/str.c
- Timestamp:
- 2020-06-18T15:39:50Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ce52c333
- Parents:
- 4f663f3e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/generic/src/str.c
r4f663f3e r28a5ebd 38 38 * strings, called just strings are encoded in UTF-8. Wide strings (encoded 39 39 * in UTF-32) are supported to a limited degree. A single character is 40 * represented as wchar_t.@n40 * represented as char32_t.@n 41 41 * 42 42 * Overview of the terminology:@n … … 46 46 * byte 8 bits stored in uint8_t (unsigned 8 bit integer) 47 47 * 48 * character UTF-32 encoded Unicode character, stored in wchar_t49 * ( signed 32 bit integer), code points 0 .. 111411148 * character UTF-32 encoded Unicode character, stored in char32_t 49 * (unsigned 32 bit integer), code points 0 .. 1114111 50 50 * are valid 51 51 * … … 57 57 * 58 58 * wide string UTF-32 encoded NULL-terminated Unicode string, 59 * wchar_t *59 * char32_t * 60 60 * 61 61 * [wide] string size number of BYTES in a [wide] string (excluding … … 96 96 * A specific character inside a [wide] string can be referred to by:@n 97 97 * 98 * pointer (char *, wchar_t *)98 * pointer (char *, char32_t *) 99 99 * byte offset (size_t) 100 100 * character index (size_t) … … 109 109 #include <stdint.h> 110 110 111 /** Check the condition if wchar_t is signed */112 #ifdef __WCHAR_UNSIGNED__113 #define WCHAR_SIGNED_CHECK(cond) (true)114 #else115 #define WCHAR_SIGNED_CHECK(cond) (cond)116 #endif117 118 111 /** Byte mask consisting of lowest @n bits (out of 8) */ 119 112 #define LO_MASK_8(n) ((uint8_t) ((1 << (n)) - 1)) … … 143 136 * 144 137 */ 145 wchar_t str_decode(const char *str, size_t *offset, size_t size)138 char32_t str_decode(const char *str, size_t *offset, size_t size) 146 139 { 147 140 if (*offset + 1 > size) … … 180 173 return U_SPECIAL; 181 174 182 wchar_t ch = b0 & LO_MASK_8(b0_bits);175 char32_t ch = b0 & LO_MASK_8(b0_bits); 183 176 184 177 /* Decode continuation bytes */ … … 191 184 192 185 /* Shift data bits to ch */ 193 ch = (ch << CONT_BITS) | ( wchar_t) (b & LO_MASK_8(CONT_BITS));186 ch = (ch << CONT_BITS) | (char32_t) (b & LO_MASK_8(CONT_BITS)); 194 187 cbytes--; 195 188 } … … 213 206 * code was invalid. 214 207 */ 215 errno_t chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)208 errno_t chr_encode(const char32_t ch, char *str, size_t *offset, size_t size) 216 209 { 217 210 if (*offset >= size) … … 340 333 * 341 334 */ 342 bool ascii_check( wchar_t ch)343 { 344 if ( WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))335 bool ascii_check(char32_t ch) 336 { 337 if (ch <= 127) 345 338 return true; 346 339 … … 353 346 * 354 347 */ 355 bool chr_check( wchar_t ch)356 { 357 if ( WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))348 bool chr_check(char32_t ch) 349 { 350 if (ch <= 1114111) 358 351 return true; 359 352 … … 381 374 int str_cmp(const char *s1, const char *s2) 382 375 { 383 wchar_t c1 = 0;384 wchar_t c2 = 0;376 char32_t c1 = 0; 377 char32_t c2 = 0; 385 378 386 379 size_t off1 = 0; … … 421 414 size_t dest_off = 0; 422 415 423 wchar_t ch;416 char32_t ch; 424 417 while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) { 425 418 if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.