Changeset 1737bfb in mainline for uspace/lib/c/generic/str.c
- Timestamp:
- 2011-10-29T17:02:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 45bf63c, e8ab32f
- Parents:
- b50bf6c2
- git-author:
- Maurizio Lombardi <m.lombardi85@…> (2011-10-29 17:02:30)
- git-committer:
- Jakub Jermar <jakub@…> (2011-10-29 17:02:30)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
rb50bf6c2 r1737bfb 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 else 887 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 } 841 895 } 842 896
Note:
See TracChangeset
for help on using the changeset viewer.