Changes in uspace/lib/c/generic/str.c [d7f6248:059a8e4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
rd7f6248 r059a8e4 261 261 } 262 262 263 /** Get size of string with size limit. 264 * 265 * Get the number of bytes which are used by the string @a str 266 * (excluding the NULL-terminator), but no more than @max_size bytes. 267 * 268 * @param str String to consider. 269 * @param max_size Maximum number of bytes to measure. 270 * 271 * @return Number of bytes used by the string 272 * 273 */ 274 size_t str_nsize(const char *str, size_t max_size) 275 { 276 size_t size = 0; 277 278 while ((*str++ != 0) && (size < max_size)) 279 size++; 280 281 return size; 282 } 283 284 /** Get size of wide string with size limit. 285 * 286 * Get the number of bytes which are used by the wide string @a str 287 * (excluding the NULL-terminator), but no more than @max_size bytes. 288 * 289 * @param str Wide string to consider. 290 * @param max_size Maximum number of bytes to measure. 291 * 292 * @return Number of bytes used by the wide string 293 * 294 */ 295 size_t wstr_nsize(const wchar_t *str, size_t max_size) 296 { 297 return (wstr_nlength(str, max_size) * sizeof(wchar_t)); 298 } 299 263 300 /** Get size of wide string with length limit. 264 301 * … … 839 876 840 877 return NULL; 878 } 879 880 /** Removes specified trailing characters from a string. 881 * 882 * @param str String to remove from. 883 * @param ch Character to remove. 884 */ 885 void str_rtrim(char *str, wchar_t ch) 886 { 887 size_t off = 0; 888 size_t pos = 0; 889 wchar_t c; 890 bool update_last_chunk = true; 891 char *last_chunk = NULL; 892 893 while ((c = str_decode(str, &off, STR_NO_LIMIT))) { 894 if (c != ch) { 895 update_last_chunk = true; 896 last_chunk = NULL; 897 } else if (update_last_chunk) { 898 update_last_chunk = false; 899 last_chunk = (str + pos); 900 } 901 pos = off; 902 } 903 904 if (last_chunk) 905 *last_chunk = '\0'; 906 } 907 908 /** Removes specified leading characters from a string. 909 * 910 * @param str String to remove from. 911 * @param ch Character to remove. 912 */ 913 void str_ltrim(char *str, wchar_t ch) 914 { 915 wchar_t acc; 916 size_t off = 0; 917 size_t pos = 0; 918 size_t str_sz = str_size(str); 919 920 while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) { 921 if (acc != ch) 922 break; 923 else 924 pos = off; 925 } 926 927 if (pos > 0) { 928 memmove(str, &str[pos], str_sz - pos); 929 pos = str_sz - pos; 930 str[str_sz - pos] = '\0'; 931 } 841 932 } 842 933 … … 1444 1535 * 1445 1536 */ 1446 int str_uint64 (const char *nptr, char **endptr, unsigned int base,1537 int str_uint64_t(const char *nptr, char **endptr, unsigned int base, 1447 1538 bool strict, uint64_t *result) 1448 1539 {
Note:
See TracChangeset
for help on using the changeset viewer.