MCPcopy Create free account
hub / github.com/apache/impala / MatchPatternT

Function MatchPatternT

be/src/gutil/strings/util.cc:829–891  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

827
828template <typename CHAR, typename NEXT>
829static bool MatchPatternT(const CHAR* eval, const CHAR* eval_end,
830 const CHAR* pattern, const CHAR* pattern_end,
831 int depth,
832 NEXT next) {
833 const int kMaxDepth = 16;
834 if (depth > kMaxDepth)
835 return false;
836
837 // Eat all the matching chars.
838 EatSameChars(&pattern, pattern_end, &eval, eval_end, next);
839
840 // If the string is empty, then the pattern must be empty too, or contains
841 // only wildcards.
842 if (eval == eval_end) {
843 EatWildcard(&pattern, pattern_end, next);
844 return pattern == pattern_end;
845 }
846
847 // Pattern is empty but not string, this is not a match.
848 if (pattern == pattern_end)
849 return false;
850
851 // If this is a question mark, then we need to compare the rest with
852 // the current string or the string with one character eaten.
853 const CHAR* next_pattern = pattern;
854 next(&next_pattern, pattern_end);
855 if (pattern[0] == '?') {
856 if (MatchPatternT(eval, eval_end, next_pattern, pattern_end,
857 depth + 1, next))
858 return true;
859 const CHAR* next_eval = eval;
860 next(&next_eval, eval_end);
861 if (MatchPatternT(next_eval, eval_end, next_pattern, pattern_end,
862 depth + 1, next))
863 return true;
864 }
865
866 // This is a *, try to match all the possible substrings with the remainder
867 // of the pattern.
868 if (pattern[0] == '*') {
869 // Collapse duplicate wild cards (********** into *) so that the
870 // method does not recurse unnecessarily. http://crbug.com/52839
871 EatWildcard(&next_pattern, pattern_end, next);
872
873 while (eval != eval_end) {
874 if (MatchPatternT(eval, eval_end, next_pattern, pattern_end,
875 depth + 1, next))
876 return true;
877 eval++;
878 }
879
880 // We reached the end of the string, let see if the pattern contains only
881 // wildcards.
882 if (eval == eval_end) {
883 EatWildcard(&pattern, pattern_end, next);
884 if (pattern != pattern_end)
885 return false;
886 return true;

Callers 1

MatchPatternFunction · 0.85

Calls 3

EatSameCharsFunction · 0.85
EatWildcardFunction · 0.85
nextFunction · 0.50

Tested by

no test coverage detected