Changes in uspace/lib/c/generic/str.c [8e893ae:1737bfb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
r8e893ae r1737bfb 46 46 #include <mem.h> 47 47 #include <str.h> 48 49 /** Check the condition if wchar_t is signed */50 #ifdef WCHAR_IS_UNSIGNED51 #define WCHAR_SIGNED_CHECK(cond) (true)52 #else53 #define WCHAR_SIGNED_CHECK(cond) (cond)54 #endif55 48 56 49 /** Byte mask consisting of lowest @n bits (out of 8) */ … … 268 261 } 269 262 270 /** Get size of string with size limit.271 *272 * Get the number of bytes which are used by the string @a str273 * (excluding the NULL-terminator), but no more than @max_size bytes.274 *275 * @param str String to consider.276 * @param max_size Maximum number of bytes to measure.277 *278 * @return Number of bytes used by the string279 *280 */281 size_t str_nsize(const char *str, size_t max_size)282 {283 size_t size = 0;284 285 while ((*str++ != 0) && (size < max_size))286 size++;287 288 return size;289 }290 291 /** Get size of wide string with size limit.292 *293 * Get the number of bytes which are used by the wide string @a str294 * (excluding the NULL-terminator), but no more than @max_size bytes.295 *296 * @param str Wide string to consider.297 * @param max_size Maximum number of bytes to measure.298 *299 * @return Number of bytes used by the wide string300 *301 */302 size_t wstr_nsize(const wchar_t *str, size_t max_size)303 {304 return (wstr_nlength(str, max_size) * sizeof(wchar_t));305 }306 307 263 /** Get size of wide string with length limit. 308 264 * … … 406 362 bool ascii_check(wchar_t ch) 407 363 { 408 if ( WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))364 if ((ch >= 0) && (ch <= 127)) 409 365 return true; 410 366 … … 419 375 bool chr_check(wchar_t ch) 420 376 { 421 if ( WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))377 if ((ch >= 0) && (ch <= 1114111)) 422 378 return true; 423 379 … … 520 476 * @param count Size of the destination buffer (must be > 0). 521 477 * @param src Source string. 522 *523 478 */ 524 479 void str_cpy(char *dest, size_t size, const char *src) … … 553 508 * @param src Source string. 554 509 * @param n Maximum number of bytes to read from @a src. 555 *556 510 */ 557 511 void str_ncpy(char *dest, size_t size, const char *src, size_t n) … … 1544 1498 * 1545 1499 */ 1546 int str_uint64 _t(const char *nptr, char **endptr, unsigned int base,1500 int str_uint64(const char *nptr, char **endptr, unsigned int base, 1547 1501 bool strict, uint64_t *result) 1548 1502 {
Note:
See TracChangeset
for help on using the changeset viewer.