int parseList(token *tok, char **s) { int firstLine, lastLine; int line; int print = 0; char *prog; firstLine = lastLine = 0; if (matchList(tok, s)) { matchWhiteSpace(tok, s); if (matchNumber(tok, s)) { firstLine = lastLine = tok->n; matchWhiteSpace(tok, s); if (matchComma(&testToken, s)) { matchWhiteSpace(tok, s); if (matchNumber(tok, s)) lastLine = tok->n; else return 0; } } prog = programGetProgram(); if (!prog) { errorSet(ERROR_OUT_OF_MEMORY); return 0; } while (*prog) { line = atoi(prog); if (lastLine && (line > lastLine)) break; if (line >= firstLine) print = 1; do { if (print) putchar(*prog); ++prog; } while (*prog != '\n'); if (print) putchar(*prog); ++prog; } return 1; } return 0; }
/* Adapted from OSC-pattern-match.c, by Matt Wright Adapted from oscpattern.c, by Matt Wright and Amar Chaudhury */ bool OscPattern::match(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 match(pattern+1,test); else return false; } switch (pattern[0]) { case 0: return test[0] == 0; case '?': return match(pattern + 1, test + 1); case '*': if (match(pattern+1, test)) return true; else return match(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 match(pattern+2,test+1); else return false; } default: if (pattern[0] == test[0]) return match(pattern+1,test+1); else return false; } }
bool CJson:: matchValues(const ValueP &value, int ind, const std::string &match, Values &values) { ValueP value1 = value; std::string match1 = match; auto p = match.find("..."); if (p != std::string::npos) { std::string lhs = match1.substr(0, p); std::string rhs = match1.substr(p + 3); return matchHier(value1, ind, lhs, rhs, values); } if (match1 != "" && match1[0] != '{') { auto p = match1.find("/"); while (p != std::string::npos) { std::string lhs = match1.substr(0, p); std::string rhs = match1.substr(p + 1); if (lhs == "") return false; if (lhs[0] == '[') { return matchArray(value1, lhs, rhs, values); } else if (lhs[0] == '{') { return matchList(value1, ind, lhs, rhs, values); } else { ValueP value2; if (! matchObject(value1, lhs, value2)) return false; value1 = value2; } match1 = rhs; p = match1.find("/"); } } if (match1 == "") return true; if (match1[0] == '[') { return matchArray(value1, match1, "", values); } else if (match1[0] == '{') { return matchList(value1, ind, match1, "", values); } else if (match1[0] == '#') { int base = 0; if (match1.size() > 1) { bool ok; base = CJson::stol(match1.substr(1), ok); } Number *n = createNumber(base + ind); values.push_back(ValueP(n)); } else { ValueP value2; if (! matchObject(value1, match1, value2)) return false; value1 = value2; if (value1) values.push_back(value1); } return true; }
JSize CBStringCompleter::Complete ( const JString& prefix, JString* maxPrefix, JXStringCompletionMenu* menu ) const { menu->RemoveAllItems(); JBoolean found; const JIndex startIndex = itsStringList->SearchSorted1(const_cast<JString*>(&prefix), JOrderedSetT::kAnyMatch, &found); const JSize stringCount = itsStringList->GetElementCount(); if (startIndex > stringCount) { maxPrefix->Clear(); return 0; } JPtrArray<JString> matchList(JPtrArrayT::kForgetAll, 100); *maxPrefix = *(itsStringList->NthElement(startIndex)); JSize matchCount = 0; JBoolean addString = kJTrue; for (JIndex i=startIndex; i<=stringCount; i++) { const JString* s = itsStringList->NthElement(i); if (!s->BeginsWith(prefix, itsCaseSensitiveFlag)) { break; } if (matchCount > 0) { const JSize matchLength = JCalcMatchLength(*maxPrefix, *s, itsCaseSensitiveFlag); const JSize prefixLength = maxPrefix->GetLength(); if (matchLength < prefixLength) { maxPrefix->RemoveSubstring(matchLength+1, prefixLength); } } matchCount++; if (itsCaseSensitiveFlag) { matchList.Append(const_cast<JString*>(s)); } else if (addString) { JString s1 = *s; MatchCase(prefix, &s1); addString = menu->AddString(s1); // must process all to get maxPrefix } } if (itsCaseSensitiveFlag && matchCount > 0) { matchList.SetSortOrder(JOrderedSetT::kSortAscending); matchList.SetCompareFunction(JCompareStringsCaseInsensitive); matchList.Sort(); assert( matchCount == matchList.GetElementCount() ); for (JIndex i=1; i<=matchCount; i++) { if (!menu->AddString(*(matchList.NthElement(i)))) { matchCount = i-1; break; } } } else if (!itsCaseSensitiveFlag) { MatchCase(prefix, maxPrefix); } return matchCount; }