Changeset b54d2f1 in mainline
- Timestamp:
- 2009-03-31T22:11:11Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e1813cf
- Parents:
- 32704cb
- Location:
- kernel/generic/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/lib/string.c
r32704cb rb54d2f1 60 60 * 61 61 * Decode a single UTF-8 character from a plain char NULL-terminated 62 * string. Decoding starts at @index and this index is incremented 63 * if the current UTF-8 string is encoded in more than a single byte. 62 * string. Decoding starts at @index and this index is moved to the 63 * beginning of the next character. In case of decoding error, 64 * index advances. However, index is never moved beyond (str+limit). 64 65 * 65 66 * @param str Plain character NULL-terminated string. … … 79 80 int cbytes; /* Number of continuation bytes. */ 80 81 81 if (*index > limit)82 if (*index + 1 > limit) 82 83 return invalch; 83 84 84 b0 = (uint8_t) str[ *index];85 b0 = (uint8_t) str[(*index)++]; 85 86 86 87 /* Determine code length. */ … … 115 116 /* Decode continuation bytes. */ 116 117 while (cbytes > 0) { 117 b = (uint8_t) str[*index + 1]; 118 ++(*index); 118 b = (uint8_t) str[(*index)++]; 119 119 120 120 /* Must be 10xxxxxx. */ … … 135 135 * Encode a single UTF-32 character as UTF-8 and store it into 136 136 * the given buffer at @index. Encoding starts at @index and 137 * this index is incremented if the UTF-8 character takes138 * more than a single byte.137 * this index is moved at the position where the next character 138 * can be written to. 139 139 * 140 140 * @param ch Input UTF-32 character. … … 157 157 int i; 158 158 159 if (*index > limit)159 if (*index >= limit) 160 160 return false; 161 161 … … 185 185 186 186 /* Check for available space in buffer. */ 187 if (*index + cbytes > limit)187 if (*index + cbytes >= limit) 188 188 return false; 189 189 … … 198 198 199 199 /* Advance index. */ 200 *index += cbytes;200 *index += (1 + cbytes); 201 201 202 202 return true; … … 220 220 size_t size = 0; 221 221 index_t index = 0; 222 223 while ((utf8_decode(str, &index, UTF8_NO_LIMIT) != 0) && (size < count)) { 222 index_t iprev; 223 wchar_t ch; 224 225 while (true) { 226 iprev = index; 227 if (size >= count) 228 break; 229 ch = utf8_decode(str, &index, UTF8_NO_LIMIT); 230 if (ch == '\0') break; 231 224 232 size++; 225 index++; 226 } 227 228 return index; 233 } 234 235 return iprev; 229 236 } 230 237 … … 284 291 while (utf8_decode(str, &index, UTF8_NO_LIMIT) != 0) { 285 292 size++; 286 index++;287 293 } 288 294 -
kernel/generic/src/printf/printf_core.c
r32704cb rb54d2f1 258 258 if (precision == 0) 259 259 precision = size; 260 260 261 261 count_t counter = 0; 262 262 width -= precision; … … 267 267 } 268 268 } 269 269 270 270 int retval; 271 271 size_t bytes = utf8_count_bytes(str, min(size, precision)); … … 279 279 counter++; 280 280 } 281 281 282 282 return ((int) counter); 283 283 } … … 586 586 { 587 587 index_t i = 0; /* Index of the currently processed character from fmt */ 588 index_t nxt = 0; 588 589 index_t j = 0; /* Index to the first not printed nonformating character */ 589 590 … … 592 593 int retval; /* Return values from nested functions */ 593 594 594 while ((uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT)) != 0) { 595 while (true) { 596 i = nxt; 597 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 598 599 if (uc == '\0') break; 600 595 601 /* Control character */ 596 602 if (uc == '%') { … … 612 618 613 619 do { 614 i ++;615 uc = utf8_decode(fmt, & i, UTF8_NO_LIMIT);620 i = nxt; 621 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 616 622 switch (uc) { 617 623 case '#': … … 638 644 int width = 0; 639 645 if (isdigit(uc)) { 640 while ((uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT)) != 0) { 646 while (true) { 647 width *= 10; 648 width += uc - '0'; 649 650 i = nxt; 651 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 652 if (uc == '\0') 653 break; 641 654 if (!isdigit(uc)) 642 655 break; 643 644 width *= 10;645 width += uc - '0';646 i++;647 656 } 648 657 } else if (uc == '*') { 649 658 /* Get width value from argument list */ 650 i ++;651 uc = utf8_decode(fmt, & i, UTF8_NO_LIMIT);659 i = nxt; 660 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 652 661 width = (int) va_arg(ap, int); 653 662 if (width < 0) { … … 661 670 int precision = 0; 662 671 if (uc == '.') { 663 i ++;664 uc = utf8_decode(fmt, & i, UTF8_NO_LIMIT);672 i = nxt; 673 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 665 674 if (isdigit(uc)) { 666 while ((uc = utf8_decode(fmt, &i, UTF8_NO_LIMIT)) != 0) { 675 while (true) { 676 precision *= 10; 677 precision += uc - '0'; 678 679 i = nxt; 680 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 681 if (uc == '\0') 682 break; 667 683 if (!isdigit(uc)) 668 684 break; 669 670 precision *= 10;671 precision += uc - '0';672 i++;673 685 } 674 } else if ( fmt[i]== '*') {686 } else if (uc == '*') { 675 687 /* Get precision value from the argument list */ 676 i ++;677 uc = utf8_decode(fmt, & i, UTF8_NO_LIMIT);688 i = nxt; 689 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 678 690 precision = (int) va_arg(ap, int); 679 691 if (precision < 0) { … … 693 705 /* Char or short */ 694 706 qualifier = PrintfQualifierShort; 695 i ++;696 uc = utf8_decode(fmt, & i, UTF8_NO_LIMIT);707 i = nxt; 708 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 697 709 if (uc == 'h') { 698 i ++;699 uc = utf8_decode(fmt, & i, UTF8_NO_LIMIT);710 i = nxt; 711 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 700 712 qualifier = PrintfQualifierByte; 701 713 } … … 704 716 /* Long or long long */ 705 717 qualifier = PrintfQualifierLong; 706 i ++;707 uc = utf8_decode(fmt, & i, UTF8_NO_LIMIT);718 i = nxt; 719 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 708 720 if (uc == 'l') { 709 i ++;710 uc = utf8_decode(fmt, & i, UTF8_NO_LIMIT);721 i = nxt; 722 uc = utf8_decode(fmt, &nxt, UTF8_NO_LIMIT); 711 723 qualifier = PrintfQualifierLongLong; 712 724 } … … 735 747 736 748 counter += retval; 737 j = i + 1;749 j = nxt; 738 750 goto next_char; 739 751 case 'c': … … 749 761 750 762 counter += retval; 751 j = i + 1;763 j = nxt; 752 764 goto next_char; 753 765 … … 853 865 854 866 counter += retval; 855 j = i + 1;867 j = nxt; 856 868 } 857 869 next_char: 858 859 i++; 870 ; 860 871 } 861 872 -
kernel/generic/src/printf/vprintf.c
r32704cb rb54d2f1 50 50 51 51 while (index < size) { 52 putchar(utf8_decode(str, &index, size - 1)); 53 index++; 52 putchar(utf8_decode(str, &index, size)); 54 53 chars++; 55 54 } … … 78 77 while ((uc = utf8_decode(str, &index, UTF8_NO_LIMIT)) != 0) { 79 78 putchar(uc); 80 index++;81 79 chars++; 82 80 } -
kernel/generic/src/printf/vsnprintf.c
r32704cb rb54d2f1 85 85 86 86 while (index < size) { 87 wchar_t uc = utf8_decode(str, &index, size - 1);88 89 if (!utf8_encode(uc, data->dst, &data->len, data->size - 2))87 wchar_t uc = utf8_decode(str, &index, size); 88 89 if (!utf8_encode(uc, data->dst, &data->len, data->size - 1)) 90 90 break; 91 92 data->len++;93 index++;94 91 } 95 92 … … 150 147 } 151 148 152 if (!utf8_encode(str[index], data->dst, &data->len, data->size - 2))149 if (!utf8_encode(str[index], data->dst, &data->len, data->size - 1)) 153 150 break; 154 151 155 data->len++;156 152 index++; 157 153 }
Note:
See TracChangeset
for help on using the changeset viewer.