bool 
cpunit::GlobMatcher::on_wildcard(const std::string& s, const std::size_t si, const std::size_t wci) const {
  CPUNIT_GLOB_TRACE("on_wildcard(s="<<s<<",si="<<si<<",wci="<<wci<<") with pattern="<<pattern);
  CPUNIT_GLOB_TRACE("            s[si]="<<s[si]<<", pattern[wci]="<<pattern[wci]);
  if (wci == pattern.length() - 1) {
      CPUNIT_GLOB_TRACE("            T <-- wci=|pattern|-1");
    return true;
  }
  for (std::size_t i=0; si+i < s.length() ; ++i) {
    if (attempt_match(s, si+i, wci+1)) {
      CPUNIT_GLOB_TRACE("            T <-- attempt_match");
      return true;
    }
  }
  return false;
}
Example #2
0
path_match_result path_match(string_view input, string_view& match_contents)
{
    if (input.length() < 2)
        return path_match_result::invalid;
    
    match_result result;
    token_kind kind;
    std::size_t length;
    
    switch (input.at(0))
    {
    case '.':
        result = match_simple_string(input.data() + 1, input.data() + input.size(), kind, length);
        if (result == match_result::complete)
        {
            match_contents = input.substr(0, length + 1);
            return path_match_result::simple_object;
        }
        else
        {
            return path_match_result::invalid;
        }
    case '[':
        result = attempt_match(input.data() + 1, input.data() + input.length(), kind, length);
        if (result == match_result::complete)
        {
            if (input.length() == length + 1 || input.at(1 + length) != ']')
                return path_match_result::invalid;
            if (kind != token_kind::string && kind != token_kind::number)
                return path_match_result::invalid;
            
            match_contents = input.substr(0, length + 2);
            return path_match_result::brace;
        }
        else
        {
            return path_match_result::invalid;
        }
    default:
        return path_match_result::invalid;
    }
}
bool
cpunit::GlobMatcher::matches(const std::string &str) const {
  CPUNIT_GLOB_TRACE("Matching '"<<str<<"' against pattern '"<<pattern<<'\'');
  return attempt_match(str, 0, 0);
}