Changeset e8ab32f in mainline for uspace/lib/c/generic/str.c


Ignore:
Timestamp:
2011-10-29T19:21:33Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c83a55c
Parents:
bf9da656 (diff), 1737bfb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/str.c

    rbf9da656 re8ab32f  
    839839       
    840840        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 */
     848void 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 */
     876void 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        }
    841895}
    842896
Note: See TracChangeset for help on using the changeset viewer.