Changeset 8227d63 in mainline for uspace/lib/c/generic/str.c


Ignore:
Timestamp:
2015-06-22T21:20:23Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1356f85a
Parents:
e96047c
Message:

UI for creating and deleting partitions.

File:
1 edited

Legend:

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

    re96047c r8227d63  
    519519        wchar_t c1 = 0;
    520520        wchar_t c2 = 0;
    521        
     521
    522522        size_t off1 = 0;
    523523        size_t off2 = 0;
     
    529529                if (c1 < c2)
    530530                        return -1;
    531                
     531
    532532                if (c1 > c2)
    533533                        return 1;
    534534
    535535                if (c1 == 0 || c2 == 0)
    536                         break;         
     536                        break;
    537537        }
    538538
     
    566566        wchar_t c1 = 0;
    567567        wchar_t c2 = 0;
    568        
     568
    569569        size_t off1 = 0;
    570570        size_t off2 = 0;
    571        
     571
    572572        size_t len = 0;
    573573
     
    578578                c1 = str_decode(s1, &off1, STR_NO_LIMIT);
    579579                c2 = str_decode(s2, &off2, STR_NO_LIMIT);
     580
     581                if (c1 < c2)
     582                        return -1;
     583
     584                if (c1 > c2)
     585                        return 1;
     586
     587                if (c1 == 0 || c2 == 0)
     588                        break;
     589
     590                ++len;
     591        }
     592
     593        return 0;
     594
     595}
     596
     597/** Compare two NULL terminated strings in case-insensitive manner.
     598 *
     599 * Do a char-by-char comparison of two NULL-terminated strings.
     600 * The strings are considered equal iff their length is equal
     601 * and both strings consist of the same sequence of characters
     602 * when converted to lower case.
     603 *
     604 * A string S1 is less than another string S2 if it has a character with
     605 * lower value at the first character position where the strings differ.
     606 * If the strings differ in length, the shorter one is treated as if
     607 * padded by characters with a value of zero.
     608 *
     609 * @param s1 First string to compare.
     610 * @param s2 Second string to compare.
     611 *
     612 * @return 0 if the strings are equal, -1 if the first is less than the second,
     613 *         1 if the second is less than the first.
     614 *
     615 */
     616int str_casecmp(const char *s1, const char *s2)
     617{
     618        wchar_t c1 = 0;
     619        wchar_t c2 = 0;
     620
     621        size_t off1 = 0;
     622        size_t off2 = 0;
     623
     624        while (true) {
     625                c1 = tolower(str_decode(s1, &off1, STR_NO_LIMIT));
     626                c2 = tolower(str_decode(s2, &off2, STR_NO_LIMIT));
     627
     628                if (c1 < c2)
     629                        return -1;
     630
     631                if (c1 > c2)
     632                        return 1;
     633
     634                if (c1 == 0 || c2 == 0)
     635                        break;
     636        }
     637
     638        return 0;
     639}
     640
     641/** Compare two NULL terminated strings with length limit in case-insensitive
     642 * manner.
     643 *
     644 * Do a char-by-char comparison of two NULL-terminated strings.
     645 * The strings are considered equal iff
     646 * min(str_length(s1), max_len) == min(str_length(s2), max_len)
     647 * and both strings consist of the same sequence of characters,
     648 * up to max_len characters.
     649 *
     650 * A string S1 is less than another string S2 if it has a character with
     651 * lower value at the first character position where the strings differ.
     652 * If the strings differ in length, the shorter one is treated as if
     653 * padded by characters with a value of zero. Only the first max_len
     654 * characters are considered.
     655 *
     656 * @param s1      First string to compare.
     657 * @param s2      Second string to compare.
     658 * @param max_len Maximum number of characters to consider.
     659 *
     660 * @return 0 if the strings are equal, -1 if the first is less than the second,
     661 *         1 if the second is less than the first.
     662 *
     663 */
     664int str_lcasecmp(const char *s1, const char *s2, size_t max_len)
     665{
     666        wchar_t c1 = 0;
     667        wchar_t c2 = 0;
     668       
     669        size_t off1 = 0;
     670        size_t off2 = 0;
     671       
     672        size_t len = 0;
     673
     674        while (true) {
     675                if (len >= max_len)
     676                        break;
     677
     678                c1 = tolower(str_decode(s1, &off1, STR_NO_LIMIT));
     679                c2 = tolower(str_decode(s2, &off2, STR_NO_LIMIT));
    580680
    581681                if (c1 < c2)
Note: See TracChangeset for help on using the changeset viewer.