Changes in boot/generic/src/str.c [28a5ebd:d066259] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/generic/src/str.c
r28a5ebd rd066259 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 char32_t.@n40 * represented as wchar_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 char32_t49 * ( unsigned 32 bit integer), code points 0 .. 111411148 * character UTF-32 encoded Unicode character, stored in wchar_t 49 * (signed 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 * char32_t *59 * wchar_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 *, char32_t *)98 * pointer (char *, wchar_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 #else 115 #define WCHAR_SIGNED_CHECK(cond) (cond) 116 #endif 117 111 118 /** Byte mask consisting of lowest @n bits (out of 8) */ 112 119 #define LO_MASK_8(n) ((uint8_t) ((1 << (n)) - 1)) … … 136 143 * 137 144 */ 138 char32_t str_decode(const char *str, size_t *offset, size_t size)145 wchar_t str_decode(const char *str, size_t *offset, size_t size) 139 146 { 140 147 if (*offset + 1 > size) … … 173 180 return U_SPECIAL; 174 181 175 char32_t ch = b0 & LO_MASK_8(b0_bits);182 wchar_t ch = b0 & LO_MASK_8(b0_bits); 176 183 177 184 /* Decode continuation bytes */ … … 184 191 185 192 /* 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)); 187 194 cbytes--; 188 195 } … … 206 213 * code was invalid. 207 214 */ 208 errno_t chr_encode(const char32_t ch, char *str, size_t *offset, size_t size)215 errno_t chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size) 209 216 { 210 217 if (*offset >= size) … … 333 340 * 334 341 */ 335 bool ascii_check( char32_t ch)336 { 337 if ( ch <= 127)342 bool ascii_check(wchar_t ch) 343 { 344 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127)) 338 345 return true; 339 346 … … 346 353 * 347 354 */ 348 bool chr_check( char32_t ch)349 { 350 if ( ch <= 1114111)355 bool chr_check(wchar_t ch) 356 { 357 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111)) 351 358 return true; 352 359 … … 374 381 int str_cmp(const char *s1, const char *s2) 375 382 { 376 char32_t c1 = 0;377 char32_t c2 = 0;383 wchar_t c1 = 0; 384 wchar_t c2 = 0; 378 385 379 386 size_t off1 = 0; … … 414 421 size_t dest_off = 0; 415 422 416 char32_t ch;423 wchar_t ch; 417 424 while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) { 418 425 if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.