@@ -24,19 +24,19 @@ constexpr size_t StringRef::npos;
24
24
25
25
// strncasecmp() is not available on non-POSIX systems, so define an
26
26
// alternative function here.
27
- static int ascii_strncasecmp (const char * LHS, const char * RHS, size_t Length ) {
28
- for (size_t I = 0 ; I < Length; ++I ) {
29
- unsigned char LHC = toLower (LHS[I] );
30
- unsigned char RHC = toLower (RHS[I] );
27
+ static int ascii_strncasecmp (StringRef LHS, StringRef RHS) {
28
+ for (auto [LC, RC] : zip_equal (LHS, RHS) ) {
29
+ unsigned char LHC = toLower (LC );
30
+ unsigned char RHC = toLower (RC );
31
31
if (LHC != RHC)
32
32
return LHC < RHC ? -1 : 1 ;
33
33
}
34
34
return 0 ;
35
35
}
36
36
37
37
int StringRef::compare_insensitive (StringRef RHS) const {
38
- if ( int Res =
39
- ascii_strncasecmp (data ( ), RHS.data (), std::min ( size (), RHS. size () )))
38
+ size_t Min = std::min ( size (), RHS. size ());
39
+ if ( int Res = ascii_strncasecmp (take_front (Min ), RHS.take_front (Min )))
40
40
return Res;
41
41
if (size () == RHS.size ())
42
42
return 0 ;
@@ -45,13 +45,12 @@ int StringRef::compare_insensitive(StringRef RHS) const {
45
45
46
46
bool StringRef::starts_with_insensitive (StringRef Prefix) const {
47
47
return size () >= Prefix.size () &&
48
- ascii_strncasecmp (data (), Prefix.data () , Prefix. size () ) == 0 ;
48
+ ascii_strncasecmp (take_front ( Prefix.size ()) , Prefix) == 0 ;
49
49
}
50
50
51
51
bool StringRef::ends_with_insensitive (StringRef Suffix) const {
52
52
return size () >= Suffix.size () &&
53
- ascii_strncasecmp (end () - Suffix.size (), Suffix.data (),
54
- Suffix.size ()) == 0 ;
53
+ ascii_strncasecmp (take_back (Suffix.size ()), Suffix) == 0 ;
55
54
}
56
55
57
56
size_t StringRef::find_insensitive (char C, size_t From) const {
0 commit comments