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


Ignore:
Timestamp:
2012-08-14T18:16:39Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
669f5cae
Parents:
76d92db1 (diff), 4802dd7 (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 mainline changes

File:
1 edited

Legend:

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

    r76d92db1 rcddcc4a3  
    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 S1 is less than another string S2 if it has a character with
     434 * lower value at the first character position where the strings differ.
     435 * If the strings differ in length, the shorter one is treated as if
     436 * padded by characters with a value of zero.
    432437 *
    433438 * @param s1 First string to compare.
    434439 * @param s2 Second string to compare.
    435440 *
    436  * @return 0 if the strings are equal, -1 if first is smaller,
    437  *         1 if second smaller.
     441 * @return 0 if the strings are equal, -1 if the first is less than the second,
     442 *         1 if the second is less than the first.
    438443 *
    439444 */
     
    466471 *
    467472 * 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.
     473 * The strings are considered equal iff
     474 * min(str_length(s1), max_len) == min(str_length(s2), max_len)
     475 * and both strings consist of the same sequence of characters,
     476 * up to max_len characters.
     477 *
     478 * A string S1 is less than another string S2 if it has a character with
     479 * lower value at the first character position where the strings differ.
     480 * If the strings differ in length, the shorter one is treated as if
     481 * padded by characters with a value of zero. Only the first max_len
     482 * characters are considered.
    470483 *
    471484 * @param s1      First string to compare.
     
    473486 * @param max_len Maximum number of characters to consider.
    474487 *
    475  * @return 0 if the strings are equal, -1 if first is smaller,
    476  *         1 if second smaller.
     488 * @return 0 if the strings are equal, -1 if the first is less than the second,
     489 *         1 if the second is less than the first.
    477490 *
    478491 */
     
    508521        return 0;
    509522
     523}
     524
     525/** Test whether p is a prefix of s.
     526 *
     527 * Do a char-by-char comparison of two NULL-terminated strings
     528 * and determine if p is a prefix of s.
     529 *
     530 * @param s The string in which to look
     531 * @param p The string to check if it is a prefix of s
     532 *
     533 * @return true iff p is prefix of s else false
     534 *
     535 */
     536bool str_test_prefix(const char *s, const char *p)
     537{
     538        wchar_t c1 = 0;
     539        wchar_t c2 = 0;
     540       
     541        size_t off1 = 0;
     542        size_t off2 = 0;
     543
     544        while (true) {
     545                c1 = str_decode(s, &off1, STR_NO_LIMIT);
     546                c2 = str_decode(p, &off2, STR_NO_LIMIT);
     547               
     548                if (c2 == 0)
     549                        return true;
     550
     551                if (c1 != c2)
     552                        return false;
     553               
     554                if (c1 == 0)
     555                        break;
     556        }
     557
     558        return false;
    510559}
    511560
     
    10851134                c = (c >= 'a' ? c - 'a' + 10 : (c >= 'A' ? c - 'A' + 10 :
    10861135                    (c <= '9' ? c - '0' : 0xff)));
    1087                 if (c > base) {
     1136                if (c >= base) {
    10881137                        break;
    10891138                }
Note: See TracChangeset for help on using the changeset viewer.