Changeset 7afb4a5 in mainline for uspace/lib/libc/generic/string.c


Ignore:
Timestamp:
2009-04-09T21:28:50Z (16 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
095003a8
Parents:
92fd52d7
Message:

Nuke strchr() and strrchr().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/string.c

    r92fd52d7 r7afb4a5  
    536536 *
    537537 * @return Pointer to character in @a str or NULL if not found.
    538  *
    539538 */
    540539const char *str_chr(const char *str, wchar_t ch)
     
    549548       
    550549        return NULL;
     550}
     551
     552/** Find last occurence of character in string.
     553 *
     554 * @param str String to search.
     555 * @param ch  Character to look for.
     556 *
     557 * @return Pointer to character in @a str or NULL if not found.
     558 */
     559const char *str_rchr(const char *str, wchar_t ch)
     560{
     561        wchar_t acc;
     562        size_t off = 0;
     563        char *res;
     564
     565        res = NULL;
     566        while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
     567                if (acc == ch)
     568                        res = (str + off);
     569        }
     570
     571        return res;
    551572}
    552573
     
    626647       
    627648        return (tolower(a[c]) - tolower(b[c]));
    628 }
    629 
    630 /** Return pointer to the first occurence of character c in string.
    631  *
    632  * @param str           Scanned string.
    633  * @param c             Searched character (taken as one byte).
    634  * @return              Pointer to the matched character or NULL if it is not
    635  *                      found in given string.
    636  */
    637 char *strchr(const char *str, int c)
    638 {
    639         while (*str != '\0') {
    640                 if (*str == (char) c)
    641                         return (char *) str;
    642                 str++;
    643         }
    644 
    645         return NULL;
    646 }
    647 
    648 /** Return pointer to the last occurence of character c in string.
    649  *
    650  * @param str           Scanned string.
    651  * @param c             Searched character (taken as one byte).
    652  * @return              Pointer to the matched character or NULL if it is not
    653  *                      found in given string.
    654  */
    655 char *strrchr(const char *str, int c)
    656 {
    657         char *retval = NULL;
    658 
    659         while (*str != '\0') {
    660                 if (*str == (char) c)
    661                         retval = (char *) str;
    662                 str++;
    663         }
    664 
    665         return (char *) retval;
    666649}
    667650
     
    870853
    871854        /* Skip over leading delimiters. */
    872         while (*s && (strchr(delim, *s) != NULL)) ++s;
     855        while (*s && (str_chr(delim, *s) != NULL)) ++s;
    873856        start = s;
    874857
    875858        /* Skip over token characters. */
    876         while (*s && (strchr(delim, *s) == NULL)) ++s;
     859        while (*s && (str_chr(delim, *s) == NULL)) ++s;
    877860        end = s;
    878861        *next = (*s ? s + 1 : s);
Note: See TracChangeset for help on using the changeset viewer.