Changeset b54d2f1 in mainline for kernel/generic/src/lib/string.c
- Timestamp:
- 2009-03-31T22:11:11Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e1813cf
- Parents:
- 32704cb
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.