File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 11#include " glob.h"
22
3+ #include < cctype>
34#include < cstdint>
45
56namespace datadog {
@@ -18,8 +19,11 @@ bool glob_match(StringView pattern, StringView subject) {
1819 Index next_p = 0 ; // next [p]attern index
1920 Index next_s = 0 ; // next [s]ubject index
2021
21- while (p < pattern.size () || s < subject.size ()) {
22- if (p < pattern.size ()) {
22+ const size_t p_size = pattern.size ();
23+ const size_t s_size = subject.size ();
24+
25+ while (p < p_size || s < s_size) {
26+ if (p < p_size) {
2327 const char pattern_char = pattern[p];
2428 switch (pattern_char) {
2529 case ' *' :
@@ -30,22 +34,22 @@ bool glob_match(StringView pattern, StringView subject) {
3034 ++p;
3135 continue ;
3236 case ' ?' :
33- if (s < subject. size () ) {
37+ if (s < s_size ) {
3438 ++p;
3539 ++s;
3640 continue ;
3741 }
3842 break ;
3943 default :
40- if (s < subject. size () && subject[s] == pattern_char) {
44+ if (s < s_size && tolower ( subject[s]) == tolower ( pattern_char) ) {
4145 ++p;
4246 ++s;
4347 continue ;
4448 }
4549 }
4650 }
4751 // Mismatch. Maybe restart.
48- if (0 < next_s && next_s <= subject. size () ) {
52+ if (0 < next_s && next_s <= s_size ) {
4953 p = next_p;
5054 s = next_s;
5155 continue ;
Original file line number Diff line number Diff line change 88
99using namespace datadog ::tracing;
1010
11- TEST_CASE (" glob" ) {
11+ TEST_CASE (" glob" , " [glob] " ) {
1212 struct TestCase {
1313 StringView pattern;
1414 StringView subject;
@@ -42,7 +42,13 @@ TEST_CASE("glob") {
4242 {" " , " " , true },
4343 {" " , " a" , false },
4444 {" *" , " " , true },
45- {" ?" , " " , false }
45+ {" ?" , " " , false },
46+
47+ // case sensitivity
48+ {" true" , " TRUE" , true },
49+ {" true" , " True" , true },
50+ {" true" , " tRue" , true },
51+ {" false" , " FALSE" , true }
4652 }));
4753 // clang-format on
4854
You can’t perform that action at this time.
0 commit comments