Changeset f25b2819 in mainline
- Timestamp:
- 2009-04-01T18:24:31Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1b0b48e0
- Parents:
- b4c4666
- Location:
- kernel/generic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/string.h
rb4c4666 rf25b2819 43 43 44 44 extern wchar_t chr_decode(const char *, size_t *, size_t); 45 extern bool chr_encode(const wchar_t, char *, size_t *, size_t limit);46 extern size_t utf8_count_bytes(const char *str, count_t count);45 extern bool chr_encode(const wchar_t, char *, size_t *, size_t); 46 extern size_t str_lsize(const char *, count_t); 47 47 extern bool ascii_check(const wchar_t ch); 48 48 extern bool unicode_check(const wchar_t ch); 49 49 50 50 extern size_t strlen(const char *str); 51 extern size_t strlen_utf8(const char *str);52 extern size_t strlen_utf32(const wchar_t *str);51 extern count_t str_length(const char *str); 52 extern count_t wstr_length(const wchar_t *str); 53 53 54 54 extern int strcmp(const char *src, const char *dst); -
kernel/generic/src/lib/string.c
rb4c4666 rf25b2819 200 200 } 201 201 202 /** Get bytes used by UTF-8 characters. 203 * 204 * Get the number of bytes (count of plain characters) which 205 * are used by a given count of UTF-8 characters in a string. 206 * As UTF-8 encoding is multibyte, there is no constant 207 * correspondence between number of characters and used bytes. 208 * 209 * @param str UTF-8 string to consider. 210 * @param count Number of UTF-8 characters to count. 202 /** Get size of string, with length limit. 203 * 204 * Get the number of bytes which are used by up to @a max_len first 205 * characters in the string @a str. If @a max_len is greater than 206 * the length of @a str, the entire string is measured. 207 * 208 * @param str String to consider. 209 * @param count Maximum number of characters to measure. 211 210 * 212 211 * @return Number of bytes used by the characters. 213 * 214 */ 215 size_t utf8_count_bytes(const char *str, count_t count) 216 { 217 size_t size = 0; 218 index_t index = 0; 219 index_t iprev; 212 */ 213 size_t str_lsize(const char *str, count_t max_len) 214 { 215 count_t len = 0; 216 size_t cur = 0; 217 size_t prev; 220 218 wchar_t ch; 221 219 222 220 while (true) { 223 iprev = index;224 if ( size >= count)221 prev = cur; 222 if (len >= max_len) 225 223 break; 226 ch = chr_decode(str, & index, UTF8_NO_LIMIT);224 ch = chr_decode(str, &cur, UTF8_NO_LIMIT); 227 225 if (ch == '\0') break; 228 226 229 size++;230 } 231 232 return iprev;227 len++; 228 } 229 230 return prev; 233 231 } 234 232 … … 263 261 * @param str NULL-terminated string. 264 262 * 265 * @return Number of characters in str.263 * @return Number of characters in @a str. 266 264 * 267 265 */ … … 274 272 } 275 273 276 /** Return number of UTF-8 characters in a string. 277 * 278 * @param str NULL-terminated UTF-8 string. 279 * 280 * @return Number of UTF-8 characters in str. 281 * 282 */ 283 size_t strlen_utf8(const char *str) 284 { 285 size_t size = 0; 286 index_t index = 0; 287 288 while (chr_decode(str, &index, UTF8_NO_LIMIT) != 0) { 289 size++; 290 } 291 292 return size; 293 } 294 295 /** Return number of UTF-32 characters in a string. 296 * 297 * @param str NULL-terminated UTF-32 string. 298 * 299 * @return Number of UTF-32 characters in str. 300 * 301 */ 302 size_t strlen_utf32(const wchar_t *str) 303 { 304 size_t size; 305 for (size = 0; str[size]; size++); 306 307 return size; 274 /** Return number of characters in a string. 275 * 276 * @param str NULL-terminated string. 277 * @return Number of characters in string. 278 */ 279 count_t str_length(const char *str) 280 { 281 count_t len = 0; 282 size_t offset = 0; 283 284 while (chr_decode(str, &offset, UTF8_NO_LIMIT) != 0) { 285 len++; 286 } 287 288 return len; 289 } 290 291 /** Return number of characters in a wide string. 292 * 293 * @param str NULL-terminated wide string. 294 * @return Number of characters in @a str. 295 */ 296 count_t wstr_length(const wchar_t *wstr) 297 { 298 count_t len; 299 300 len = 0; 301 while (*wstr++ != '\0') 302 ++len; 303 304 return len; 308 305 } 309 306 -
kernel/generic/src/printf/printf_core.c
rb4c4666 rf25b2819 255 255 256 256 /* Print leading spaces */ 257 size_t size = str len_utf8(str);257 size_t size = str_length(str); 258 258 if (precision == 0) 259 259 precision = size; … … 269 269 270 270 int retval; 271 size_t bytes = utf8_count_bytes(str, min(size, precision));271 size_t bytes = str_lsize(str, min(size, precision)); 272 272 if ((retval = printf_putnchars_utf8(str, bytes, ps)) < 0) 273 273 return -counter; … … 299 299 300 300 /* Print leading spaces */ 301 size_t size = strlen_utf32(str);301 size_t size = wstr_length(str); 302 302 if (precision == 0) 303 303 precision = size;
Note:
See TracChangeset
for help on using the changeset viewer.