Fork us on GitHub Follow us on Facebook Follow us on Twitter

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


Ignore:
Timestamp:
2012-07-30T20:01:02Z (9 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master
Children:
542e819, beb9336
Parents:
c15849c (diff), 597b12e (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

    rc15849c rbd29f9c9  
    428428 *
    429429 * Do a char-by-char comparison of two NULL-terminated strings.
    430  * The strings are considered equal iff they consist of the same
    431  * characters on the minimum of their lengths.
     430 * The strings are considered equal iff their length is equal
     431 * and both strings consist of the same sequence of characters.
     432 *
     433 * A string is smaller than another string iff it is shorter or
     434 * has a character with lower value at the first position where
     435 * the strings differ.
    432436 *
    433437 * @param s1 First string to compare.
     
    466470 *
    467471 * Do a char-by-char comparison of two NULL-terminated strings.
    468  * The strings are considered equal iff they consist of the same
    469  * characters on the minimum of their lengths and the length limit.
     472 * The strings are considered equal iff
     473 * min(str_length(s1), max_len) == min(str_length(s2), max_len)
     474 * and both strings consist of the same sequence of characters,
     475 * up to max_len characters.
     476 *
     477 * A string is smaller than another string iff it is shorter or
     478 * has a character with lower value at the first position where
     479 * the strings differ, considering only first max_len characters.
    470480 *
    471481 * @param s1      First string to compare.
     
    508518        return 0;
    509519
     520}
     521
     522/** Test whether p is a prefix of s.
     523 *
     524 * Do a char-by-char comparison of two NULL-terminated strings
     525 * and determine if p is a prefix of s.
     526 *
     527 * @param s The string in which to look
     528 * @param p The string to check if it is a prefix of s
     529 *
     530 * @return true iff p is prefix of s else false
     531 *
     532 */
     533bool str_test_prefix(const char *s, const char *p)
     534{
     535        wchar_t c1 = 0;
     536        wchar_t c2 = 0;
     537       
     538        size_t off1 = 0;
     539        size_t off2 = 0;
     540
     541        while (true) {
     542                c1 = str_decode(s, &off1, STR_NO_LIMIT);
     543                c2 = str_decode(p, &off2, STR_NO_LIMIT);
     544               
     545                if (c2 == 0)
     546                        return true;
     547
     548                if (c1 != c2)
     549                        return false;
     550               
     551                if (c1 == 0)
     552                        break;
     553        }
     554
     555        return false;
    510556}
    511557
Note: See TracChangeset for help on using the changeset viewer.