Exemple #1
0
/**
 * @brief Matches an OSC address pattern starting with literal character,
 * bracketed list or curly braced list with the next character(s) in the target
 * OSC address.
 *
 * The oscAddressPattern and oscAddress pointers are advanced to the character
 * proceeding the matched sequence only if a match is found.  The pointers are
 * not modified if a match cannot be found.
 *
 * This is an internal function and cannot be called by the user application.
 *
 * @param oscAddressPattern Pointer to first character of OSC address pattern.
 * @param oscAddress Pointer to first character of target OSC address.
 * @param isPartial Flag indicating if a partial match is acceptable.
 * @return true if OSC address pattern and target OSC address match.
 */
static bool MatchCharacter(const char * * const oscAddressPattern, const char * * const oscAddress, const bool isPartial) {
    const char * oscAddressPatternCache = *oscAddressPattern;
    const char * oscAddressCache = *oscAddress;
    switch (**oscAddressPattern) {
        case '[':
            if (MatchBrackets(oscAddressPattern, oscAddress) == true) {
                return true;
            }
            break;
        case ']':
            break; // fail: unbalanced brackets
        case '{':
            if (MatchCurlyBraces(oscAddressPattern, oscAddress, isPartial) == true) {
                return true;
            }
            break;
        case '}':
            break; // fail: unbalanced curly braces
        default:
            if ((**oscAddressPattern == **oscAddress) || (**oscAddressPattern == '?')) {
                (*oscAddressPattern)++;
                (*oscAddress)++;
                return true;
            }
            break;
    }
    *oscAddressPattern = oscAddressPatternCache;
    *oscAddress = oscAddressCache;
    return false;
}
bool Osc_PatternMatch(const char *  pattern, const char * test)
{
    theWholePattern = pattern;

    if (pattern == 0 || pattern[0] == 0)
    {
        return test[0] == 0;
    }

    if (test[0] == 0)
    {
        if (pattern[0] == '*')
            return Osc_PatternMatch(pattern+1,test);
        else
            return false;
    }

    switch (pattern[0])
    {
    case 0:
        return test[0] == 0;
    case '?':
        return Osc_PatternMatch(pattern + 1, test + 1);
    case '*':
        if (Osc_PatternMatch(pattern+1, test))
            return true;
        else
            return Osc_PatternMatch(pattern, test+1);
    case ']':
    case '}':
        // OSCWarning("Spurious %c in pattern \".../%s/...\"",pattern[0], theWholePattern);
        return false;
    case '[':
        return MatchBrackets (pattern,test);
    case '{':
        return MatchList (pattern,test);
    case '\\':
        if (pattern[1] == 0)
            return test[0] == 0;
        else
        {
            if (pattern[1] == test[0])
                return Osc_PatternMatch(pattern+2,test+1);
            else
                return false;
        }
    default:
        if (pattern[0] == test[0])
            return Osc_PatternMatch(pattern+1,test+1);
        else
            return false;
    }
}
Exemple #3
0
Boolean PatternMatch (const char *  pattern, const char * test) {
  theWholePattern = pattern;
  
  if (pattern == 0 || pattern[0] == 0) {
    return test[0] == 0;
  } 
  
  if (test[0] == 0) {
    if (pattern[0] == '*')
      return PatternMatch (pattern+1,test);
    else
      return FALSE;
  }

  switch (pattern[0]) {
    case 0      : return test[0] == 0;
    case '?'    : return PatternMatch (pattern + 1, test + 1);
    case '*'    : 
      if (PatternMatch (pattern+1, test)) {
        return TRUE;
      } else {
	return PatternMatch (pattern, test+1);
      }
    case ']'    :
    case '}'    :
      OSCWarning("Spurious %c in pattern \".../%s/...\"",pattern[0], theWholePattern);
      return FALSE;
    case '['    :
      return MatchBrackets (pattern,test);
    case '{'    :
      return MatchList (pattern,test);
    case '\\'   :  
      if (pattern[1] == 0) {
	return test[0] == 0;
      } else if (pattern[1] == test[0]) {
	return PatternMatch (pattern+2,test+1);
      } else {
	return FALSE;
      }
    default     :
      if (pattern[0] == test[0]) {
	return PatternMatch (pattern+1,test+1);
      } else {
	return FALSE;
      }
  }
}
Exemple #4
0
static int PatternMatch (const char *  pattern, const char * test)
{
    theWholePattern = pattern;
  
    if (pattern == 0 || pattern[0] == 0) return test[0] == 0;
  
    if (test[0] == 0)
    {
        if (pattern[0] == '*') return PatternMatch (pattern+1, test);
        return 0;
    }

    switch (pattern[0])
    {
        case 0:
            return test[0] == 0;
        case '?':
            return PatternMatch (pattern+1, test+1);
        case '*': 
            if (PatternMatch (pattern+1, test)) return 1;
            return PatternMatch (pattern, test+1);
        case ']':
        case '}':
                  error("routeOSC: Spurious %c in pattern \".../%s/...\"",pattern[0], theWholePattern);
            return 0;
        case '[':
            return MatchBrackets (pattern,test);
        case '{':
            return MatchList (pattern,test);
        case '\\':  
            if (pattern[1] == 0) return test[0] == 0;
            if (pattern[1] == test[0]) return PatternMatch (pattern+2,test+1);
            return 0;
        default:
            if (pattern[0] == test[0]) return PatternMatch (pattern+1,test+1);
            return 0;
    }
}