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

Function EatSameChars

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

Source from the content-addressed store, hash-verified

774// Move the strings pointers to the point where they start to differ.
775template <typename CHAR, typename NEXT>
776static void EatSameChars(const CHAR** pattern, const CHAR* pattern_end,
777 const CHAR** string, const CHAR* string_end,
778 NEXT next) {
779 const CHAR* escape = nullptr;
780 while (*pattern != pattern_end && *string != string_end) {
781 if (!escape && IsWildcard(**pattern)) {
782 // We don't want to match wildcard here, except if it's escaped.
783 return;
784 }
785
786 // Check if the escapement char is found. If so, skip it and move to the
787 // next character.
788 if (!escape && **pattern == '\\') {
789 escape = *pattern;
790 next(pattern, pattern_end);
791 continue;
792 }
793
794 // Check if the chars match, if so, increment the ptrs.
795 const CHAR* pattern_next = *pattern;
796 const CHAR* string_next = *string;
797 Rune pattern_char = next(&pattern_next, pattern_end);
798 if (pattern_char == next(&string_next, string_end) &&
799 pattern_char != Runeerror &&
800 pattern_char <= Runemax) {
801 *pattern = pattern_next;
802 *string = string_next;
803 } else {
804 // Uh ho, it did not match, we are done. If the last char was an
805 // escapement, that means that it was an error to advance the ptr here,
806 // let's put it back where it was. This also mean that the MatchPattern
807 // function will return false because if we can't match an escape char
808 // here, then no one will.
809 if (escape) {
810 *pattern = escape;
811 }
812 return;
813 }
814
815 escape = nullptr;
816 }
817}
818
819template <typename CHAR, typename NEXT>
820static void EatWildcard(const CHAR** pattern, const CHAR* end, NEXT next) {

Callers 1

MatchPatternTFunction · 0.85

Calls 2

IsWildcardFunction · 0.85
nextFunction · 0.50

Tested by

no test coverage detected