2 * File: GlobMatcher.cpp
4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
8 #include "GlobMatcher.h"
11 #define NEGATE '^' // std cset negation char
14 using namespace elftosb;
16 //! The glob pattern must match the \e entire test value argument in order
17 //! for the match to be considered successful. Thus, even if, for example,
18 //! the pattern matches all but the last character the result will be false.
20 //! \retval true The test value does match the glob pattern.
21 //! \retval false The test value does not match the glob pattern.
22 bool GlobMatcher::match(const std::string & testValue)
24 return globMatch(testValue.c_str(), m_pattern.c_str());
27 //! \note This glob implementation was originally written by ozan s. yigit in
28 //! December 1994. This is public domain source code.
29 bool GlobMatcher::globMatch(const char *str, const char *p)
36 if (!*str && *p != '*')
48 if (*p != '?' && *p != '[' && *p != '\\')
49 while (*str && *p != *str)
53 if (globMatch(str, p))
64 // set specification is inclusive, that is [a-z] is a, z and
65 // everything in between. this means [z-a] may be interpreted
66 // as a set that contains z, a and nothing in between.
77 while (!match && (c = *p++)) {
80 if (*p == '-') { // c-c
84 if (*str == c || *str == *p ||
85 (*str > c && *str < *p))
108 // if there is a match, skip past the cset and continue on
109 while (*p && *p != ']')