MCPcopy Create free account
hub / github.com/F-Stack/f-stack / do_case_compare

Function do_case_compare

freebsd/contrib/openzfs/module/unicode/u8_textprep.c:563–680  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

561 * faster processing time.
562 */
563static int
564do_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. */

Callers 1

u8_strcmpFunction · 0.85

Calls 2

do_case_convFunction · 0.85
strcmpFunction · 0.85

Tested by

no test coverage detected