Changes in uspace/lib/c/generic/str.c [a18a8b9:1558d85] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
ra18a8b9 r1558d85 45 45 #include <align.h> 46 46 #include <mem.h> 47 #include <str.h>48 47 49 48 /** Check the condition if wchar_t is signed */ … … 519 518 wchar_t c1 = 0; 520 519 wchar_t c2 = 0; 521 520 522 521 size_t off1 = 0; 523 522 size_t off2 = 0; … … 529 528 if (c1 < c2) 530 529 return -1; 531 530 532 531 if (c1 > c2) 533 532 return 1; … … 566 565 wchar_t c1 = 0; 567 566 wchar_t c2 = 0; 568 567 569 568 size_t off1 = 0; 570 569 size_t off2 = 0; 571 570 572 571 size_t len = 0; 573 572 … … 589 588 590 589 ++len; 590 } 591 592 return 0; 593 594 } 595 596 /** Compare two NULL terminated strings in case-insensitive manner. 597 * 598 * Do a char-by-char comparison of two NULL-terminated strings. 599 * The strings are considered equal iff their length is equal 600 * and both strings consist of the same sequence of characters 601 * when converted to lower case. 602 * 603 * A string S1 is less than another string S2 if it has a character with 604 * lower value at the first character position where the strings differ. 605 * If the strings differ in length, the shorter one is treated as if 606 * padded by characters with a value of zero. 607 * 608 * @param s1 First string to compare. 609 * @param s2 Second string to compare. 610 * 611 * @return 0 if the strings are equal, -1 if the first is less than the second, 612 * 1 if the second is less than the first. 613 * 614 */ 615 int str_casecmp(const char *s1, const char *s2) 616 { 617 wchar_t c1 = 0; 618 wchar_t c2 = 0; 619 620 size_t off1 = 0; 621 size_t off2 = 0; 622 623 while (true) { 624 c1 = tolower(str_decode(s1, &off1, STR_NO_LIMIT)); 625 c2 = tolower(str_decode(s2, &off2, STR_NO_LIMIT)); 626 627 if (c1 < c2) 628 return -1; 629 630 if (c1 > c2) 631 return 1; 632 633 if (c1 == 0 || c2 == 0) 634 break; 635 } 636 637 return 0; 638 } 639 640 /** Compare two NULL terminated strings with length limit in case-insensitive 641 * manner. 642 * 643 * Do a char-by-char comparison of two NULL-terminated strings. 644 * The strings are considered equal iff 645 * min(str_length(s1), max_len) == min(str_length(s2), max_len) 646 * and both strings consist of the same sequence of characters, 647 * up to max_len characters. 648 * 649 * A string S1 is less than another string S2 if it has a character with 650 * lower value at the first character position where the strings differ. 651 * If the strings differ in length, the shorter one is treated as if 652 * padded by characters with a value of zero. Only the first max_len 653 * characters are considered. 654 * 655 * @param s1 First string to compare. 656 * @param s2 Second string to compare. 657 * @param max_len Maximum number of characters to consider. 658 * 659 * @return 0 if the strings are equal, -1 if the first is less than the second, 660 * 1 if the second is less than the first. 661 * 662 */ 663 int str_lcasecmp(const char *s1, const char *s2, size_t max_len) 664 { 665 wchar_t c1 = 0; 666 wchar_t c2 = 0; 667 668 size_t off1 = 0; 669 size_t off2 = 0; 670 671 size_t len = 0; 672 673 while (true) { 674 if (len >= max_len) 675 break; 676 677 c1 = tolower(str_decode(s1, &off1, STR_NO_LIMIT)); 678 c2 = tolower(str_decode(s2, &off2, STR_NO_LIMIT)); 679 680 if (c1 < c2) 681 return -1; 682 683 if (c1 > c2) 684 return 1; 685 686 if (c1 == 0 || c2 == 0) 687 break; 688 689 ++len; 591 690 } 592 691 … … 1058 1157 memmove(str, &str[pos], str_sz - pos); 1059 1158 pos = str_sz - pos; 1060 str[ pos] = '\0';1159 str[str_sz - pos] = '\0'; 1061 1160 } 1062 1161 } … … 1151 1250 } 1152 1251 1153 /** Convert string to a number. 1252 /** Convert string to a number. 1154 1253 * Core of strtol and strtoul functions. 1155 1254 * … … 1197 1296 str += 2; 1198 1297 } 1199 } 1298 } 1200 1299 } 1201 1300 … … 1236 1335 *endptr = (char *) str; 1237 1336 1238 if (nptr == str) { 1337 if (nptr == str) { 1239 1338 /*FIXME: errno = EINVAL*/ 1240 1339 return 0; … … 1267 1366 if ((sgn) && (number == (unsigned long) (LONG_MAX) + 1)) { 1268 1367 /* FIXME: set 0 to errno */ 1269 return number; 1368 return number; 1270 1369 } 1271 1370 /* FIXME: set ERANGE to errno */ 1272 return (sgn ? LONG_MIN : LONG_MAX); 1371 return (sgn ? LONG_MIN : LONG_MAX); 1273 1372 } 1274 1373
Note:
See TracChangeset
for help on using the changeset viewer.