Changes in uspace/lib/c/generic/str.c [8227d63:ee3f6f6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
r8227d63 ree3f6f6 519 519 wchar_t c1 = 0; 520 520 wchar_t c2 = 0; 521 521 522 522 size_t off1 = 0; 523 523 size_t off2 = 0; … … 529 529 if (c1 < c2) 530 530 return -1; 531 531 532 532 if (c1 > c2) 533 533 return 1; 534 534 535 535 if (c1 == 0 || c2 == 0) 536 break; 536 break; 537 537 } 538 538 … … 566 566 wchar_t c1 = 0; 567 567 wchar_t c2 = 0; 568 568 569 569 size_t off1 = 0; 570 570 size_t off2 = 0; 571 571 572 572 size_t len = 0; 573 573 … … 578 578 c1 = str_decode(s1, &off1, STR_NO_LIMIT); 579 579 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 equal601 * and both strings consist of the same sequence of characters602 * when converted to lower case.603 *604 * A string S1 is less than another string S2 if it has a character with605 * lower value at the first character position where the strings differ.606 * If the strings differ in length, the shorter one is treated as if607 * 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 */616 int 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-insensitive642 * manner.643 *644 * Do a char-by-char comparison of two NULL-terminated strings.645 * The strings are considered equal iff646 * 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 with651 * lower value at the first character position where the strings differ.652 * If the strings differ in length, the shorter one is treated as if653 * padded by characters with a value of zero. Only the first max_len654 * 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 */664 int 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));680 580 681 581 if (c1 < c2)
Note:
See TracChangeset
for help on using the changeset viewer.