Changes in uspace/lib/c/generic/str.c [1737bfb:d7f6248] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
r1737bfb rd7f6248 839 839 840 840 return NULL; 841 }842 843 /** Removes specified trailing characters from a string.844 *845 * @param str String to remove from.846 * @param ch Character to remove.847 */848 void str_rtrim(char *str, wchar_t ch)849 {850 size_t off = 0;851 size_t pos = 0;852 wchar_t c;853 bool update_last_chunk = true;854 char *last_chunk = NULL;855 856 while ((c = str_decode(str, &off, STR_NO_LIMIT))) {857 if (c != ch) {858 update_last_chunk = true;859 last_chunk = NULL;860 } else if (update_last_chunk) {861 update_last_chunk = false;862 last_chunk = (str + pos);863 }864 pos = off;865 }866 867 if (last_chunk)868 *last_chunk = '\0';869 }870 871 /** Removes specified leading characters from a string.872 *873 * @param str String to remove from.874 * @param ch Character to remove.875 */876 void str_ltrim(char *str, wchar_t ch)877 {878 wchar_t acc;879 size_t off = 0;880 size_t pos = 0;881 size_t str_sz = str_size(str);882 883 while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {884 if (acc != ch)885 break;886 else887 pos = off;888 }889 890 if (pos > 0) {891 memmove(str, &str[pos], str_sz - pos);892 pos = str_sz - pos;893 str[str_sz - pos] = '\0';894 }895 841 } 896 842
Note:
See TracChangeset
for help on using the changeset viewer.