23
23
24
24
namespace FSTR
25
25
{
26
- bool String::equals (const char * cstr, size_t len ) const
26
+ bool String::equals (const char * cstr, size_t clen, bool ignoreCase ) const
27
27
{
28
28
// Unlikely we'd want an empty flash string, but check anyway
29
29
if (cstr == nullptr ) {
30
30
return length () == 0 ;
31
31
}
32
- // Don't use strcmp as our data may contain nuls
33
- if (len == 0 ) {
34
- len = strlen (cstr);
35
- }
36
- if (len != length ()) {
32
+ auto len = length ();
33
+ if (clen != len) {
37
34
return false ;
38
35
}
39
36
LOAD_FSTR (buf, *this );
37
+ if (ignoreCase) {
38
+ return memicmp (buf, cstr, len) == 0 ;
39
+ }
40
40
return memcmp (buf, cstr, len) == 0 ;
41
41
}
42
42
43
- bool String::equals (const String& str) const
43
+ bool String::equals (const char * cstr, bool ignoreCase) const
44
+ {
45
+ return equals (cstr, cstr ? strlen (cstr) : 0 , ignoreCase);
46
+ }
47
+
48
+ bool String::equals (const String& str, bool ignoreCase) const
44
49
{
45
- if (data () == str.data ()) {
50
+ auto dataptr = data ();
51
+ auto strdata = str.data ();
52
+ if (dataptr == strdata) {
46
53
return true ;
47
54
}
48
- if (length () != str.length ()) {
55
+ auto len = length ();
56
+ if (len != str.length ()) {
49
57
return false ;
50
58
}
51
- return memcmp_aligned (data (), str.data (), length ()) == 0 ;
59
+ if (ignoreCase) {
60
+ LOAD_FSTR (buf, *this );
61
+ return memicmp (dataptr, buf, len) == 0 ;
62
+ }
63
+ return memcmp_aligned (dataptr, strdata, len) == 0 ;
52
64
}
53
65
54
66
/* Wiring String support */
@@ -58,25 +70,18 @@ String::operator WString() const
58
70
return isNull () ? WString () : WString (data (), length ());
59
71
}
60
72
61
- bool String::equals (const WString& str) const
73
+ bool String::equals (const WString& str, bool ignoreCase ) const
62
74
{
63
75
auto len = str.length ();
64
76
if (len != length ()) {
65
77
return false ;
66
78
}
67
79
// @todo optimise memcmp_P then we won't need to load entire String into RAM first
68
80
LOAD_FSTR (buf, *this );
69
- return memcmp (buf, str.c_str (), len) == 0 ;
70
- }
71
-
72
- bool String::equalsIgnoreCase (const WString& str) const
73
- {
74
- auto len = str.length ();
75
- if (len != length ()) {
76
- return false ;
81
+ if (ignoreCase) {
82
+ return memicmp (buf, str.c_str (), len) == 0 ;
77
83
}
78
- LOAD_FSTR (buf, *this );
79
- return memicmp (buf, str.c_str (), len) == 0 ;
84
+ return memcmp (buf, str.c_str (), len) == 0 ;
80
85
}
81
86
82
87
} // namespace FSTR
0 commit comments