* The do_case_compare() function compares the two input strings, s1 and s2, * one character at a time doing case conversions if applicable and return * the comparison result as like strcmp(). * * Since, in empirical sense, most of text data are 7-bit ASCII characters, * we treat the 7-bit ASCII characters as a special case trying to yield * faster processing time. */
| 561 | * faster processing time. |
| 562 | */ |
| 563 | static int |
| 564 | do_case_compare(size_t uv, uchar_t *s1, uchar_t *s2, size_t n1, |
| 565 | size_t n2, boolean_t is_it_toupper, int *errnum) |
| 566 | { |
| 567 | int f; |
| 568 | int sz1; |
| 569 | int sz2; |
| 570 | size_t j; |
| 571 | size_t i1; |
| 572 | size_t i2; |
| 573 | uchar_t u8s1[U8_MB_CUR_MAX + 1]; |
| 574 | uchar_t u8s2[U8_MB_CUR_MAX + 1]; |
| 575 | |
| 576 | i1 = i2 = 0; |
| 577 | while (i1 < n1 && i2 < n2) { |
| 578 | /* |
| 579 | * Find out what would be the byte length for this UTF-8 |
| 580 | * character at string s1 and also find out if this is |
| 581 | * an illegal start byte or not and if so, issue a proper |
| 582 | * error number and yet treat this byte as a character. |
| 583 | */ |
| 584 | sz1 = u8_number_of_bytes[*s1]; |
| 585 | if (sz1 < 0) { |
| 586 | *errnum = EILSEQ; |
| 587 | sz1 = 1; |
| 588 | } |
| 589 | |
| 590 | /* |
| 591 | * For 7-bit ASCII characters mainly, we do a quick case |
| 592 | * conversion right at here. |
| 593 | * |
| 594 | * If we don't have enough bytes for this character, issue |
| 595 | * an EINVAL error and use what are available. |
| 596 | * |
| 597 | * If we have enough bytes, find out if there is |
| 598 | * a corresponding uppercase character and if so, copy over |
| 599 | * the bytes for a comparison later. If there is no |
| 600 | * corresponding uppercase character, then, use what we have |
| 601 | * for the comparison. |
| 602 | */ |
| 603 | if (sz1 == 1) { |
| 604 | if (is_it_toupper) |
| 605 | u8s1[0] = U8_ASCII_TOUPPER(*s1); |
| 606 | else |
| 607 | u8s1[0] = U8_ASCII_TOLOWER(*s1); |
| 608 | s1++; |
| 609 | u8s1[1] = '\0'; |
| 610 | } else if ((i1 + sz1) > n1) { |
| 611 | *errnum = EINVAL; |
| 612 | for (j = 0; (i1 + j) < n1; ) |
| 613 | u8s1[j++] = *s1++; |
| 614 | u8s1[j] = '\0'; |
| 615 | } else { |
| 616 | (void) do_case_conv(uv, u8s1, s1, sz1, is_it_toupper); |
| 617 | s1 += sz1; |
| 618 | } |
| 619 | |
| 620 | /* Do the same for the string s2. */ |
no test coverage detected