bool elementPatternMatches(const char* pattern, const HTMLInputElement* inputElement) { WTF::String patternString(pattern); if (!inputElement || patternString.isEmpty()) return false; if (inputElement->fastHasAttribute(HTMLNames::patternAttr)) { WTF::String patternAttribute = inputElement->fastGetAttribute(HTMLNames::patternAttr); if (patternAttribute.startsWith(patternString)) { // The pattern is for hexadecimal, make sure nothing else is permitted. // Check if it was an exact match. if (patternAttribute.length() == patternString.length()) return true; // Check for * if (patternAttribute.length() == patternString.length() + 1 && patternAttribute[patternString.length()] == '*') return true; // Is the regex specifying a character count? if (patternAttribute[patternString.length()] != '{' || !patternAttribute.endsWith('}')) return false; // Make sure the number in the regex is actually a number. unsigned count = 0; patternString = patternString + "{%d}"; return (sscanf(patternAttribute.latin1().data(), patternString.latin1().data() + '\0', &count) == 1) && count > 0; } } return false; }
bool mitk::StateMachineFactory::LoadStandardBehavior() { Module* module = ModuleRegistry::GetModule("Mitk"); ModuleResource resource = module->GetResource("Interactions/Legacy/StateMachine.xml"); if (!resource.IsValid()) { mitkThrow()<< ("Resource not valid. State machine pattern not found:Interactions/Legacy/StateMachine.xml" ); } mitk::ModuleResourceStream stream(resource); std::string patternString((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>()); return this->LoadBehaviorString(patternString); }
U_DRAFT int32_t U_EXPORT2 udatpg_getBaseSkeleton(UDateTimePatternGenerator *dtpg, const UChar *pattern, int32_t length, UChar *skeleton, int32_t capacity, UErrorCode *pErrorCode) { if(U_FAILURE(*pErrorCode)) { return 0; } if(pattern==NULL && length!=0) { *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; return 0; } UnicodeString patternString((UBool)(length<0), pattern, length); UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBaseSkeleton(patternString, *pErrorCode); return result.extract(skeleton, capacity, *pErrorCode); }
// save autoreplace entries to configuration void Autoreplace_Config::saveSettings() { // get configuration object KSharedConfigPtr config=KGlobal::config(); // delete all patterns config->deleteGroup("Autoreplace List"); // create new empty autoreplace group KConfigGroup grp = config->group("Autoreplace List"); // create empty list QList<QStringList> newList=currentAutoreplaceList(); // check if there are any patterns in the list view if(newList.count()) { // go through all patterns and save them into the configuration QString regexString("Regex"); QString directString("Direction"); QString patternString("Pattern"); QString replaceString("Replace"); for(int index=0;index<newList.count();index++) { // write the current entry's pattern and replacement (adds a "#" to preserve blanks at the end of the line) QString indexString(QString::number(index)); QStringList definition = newList[index]; grp.writeEntry(regexString + indexString,definition.at(0)); //regex status grp.writeEntry(directString + indexString,definition.at(1)); //direction grp.writeEntry(patternString + indexString,QString(definition.at(2)+'#')); //pattern grp.writeEntry(replaceString + indexString,QString(definition.at(3)+'#')); //replace } // for } // if there were no entries at all, write a dummy entry to prevent KConfigXT from "optimizing" // the group out, which would in turn make konvi restore the default entries else grp.writeEntry("Empty List",QString()); // set internal autoreplace list Preferences::setAutoreplaceList(newList); // remember autoreplace list for hasChanged() m_oldAutoreplaceList=newList; }
bool TrackerString::MatchesRegExp(const char* pattern, bool caseSensitivity) const { BString patternString(pattern); BString textString(String()); if (caseSensitivity == false) { patternString.ToLower(); textString.ToLower(); } RegExp expression(patternString); if (expression.InitCheck() != B_OK) return false; return expression.Matches(textString); }
U_CFUNC int32_t getAt(const UChar* source, int32_t srcLen, UChar** dest, int32_t destCapacity, int32_t index, UParseCommentsOption option, UErrorCode* status){ if(status == NULL || U_FAILURE(*status)){ return 0; } UnicodeString stringArray[MAX_SPLIT_STRINGS]; RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), UREGEX_MULTILINE, *status); UnicodeString src (source, srcLen); if (U_FAILURE(*status)) { return 0; } int32_t retLen = pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); UnicodeString patternString(patternStrings[option]); RegexMatcher matcher(patternString, UREGEX_DOTALL, *status); if (U_FAILURE(*status)) { return 0; } int32_t count = 0; for(int32_t i=0; i<retLen; i++){ matcher.reset(stringArray[i]); if(matcher.lookingAt(*status)){ if(count == index){ UnicodeString out = matcher.group(1, *status); return out.extract(*dest, destCapacity,*status); } count++; } } return 0; }
void GrepDialog::search() { GrepJob* job = new GrepJob(); job->setPatternString(patternString()); job->templateString = templateString(); job->filesString = filesString(); job->excludeString = excludeString(); job->directory = directory(); job->useProjectFilesFlag = useProjectFilesFlag(); job->regexpFlag = regexpFlag(); job->recursiveFlag = recursiveFlag(); job->noFindErrorsFlag = noFindErrorsFlag(); job->caseSensitiveFlag = caseSensitiveFlag(); kDebug() << "registering job"; KDevelop::ICore::self()->runController()->registerJob(job); m_plugin->rememberSearchDirectory(directory().toLocalFile(KUrl::AddTrailingSlash)); close(); }
U_CFUNC int32_t getCount(const UChar* source, int32_t srcLen, UParseCommentsOption option, UErrorCode *status){ if(status == NULL || U_FAILURE(*status)){ return 0; } UnicodeString stringArray[MAX_SPLIT_STRINGS]; RegexPattern *pattern = RegexPattern::compile(UnicodeString("@"), UREGEX_MULTILINE, *status); UnicodeString src (source, srcLen); if (U_FAILURE(*status)) { return 0; } int32_t retLen = pattern->split(src, stringArray, MAX_SPLIT_STRINGS, *status); UnicodeString patternString(patternStrings[option]); RegexMatcher matcher(patternString, UREGEX_DOTALL, *status); if (U_FAILURE(*status)) { return 0; } int32_t count = 0; for(int32_t i=0; i<retLen; i++){ matcher.reset(stringArray[i]); if(matcher.lookingAt(*status)){ count++; } } if(option == UPC_TRANSLATE && count > 1){ fprintf(stderr, "Multiple @translate tags cannot be supported.\n"); exit(U_UNSUPPORTED_ERROR); } return count; }
StringSearchPerformanceTest::StringSearchPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status) :UPerfTest(argc,argv,status){ int32_t start, end; #ifdef TEST_BOYER_MOORE_SEARCH bms = NULL; #else srch = NULL; #endif pttrn = NULL; if(status== U_ILLEGAL_ARGUMENT_ERROR || line_mode){ fprintf(stderr,gUsageString, "strsrchperf"); return; } /* Get the Text */ src = getBuffer(srcLen, status); #if 0 /* Get a word to find. Do this by selecting a random word with a word breakiterator. */ UBreakIterator* brk = ubrk_open(UBRK_WORD, locale, src, srcLen, &status); if(U_FAILURE(status)){ fprintf(stderr, "FAILED to create pattern for searching. Error: %s\n", u_errorName(status)); return; } start = ubrk_preceding(brk, 1000); end = ubrk_following(brk, start); pttrnLen = end - start; UChar* temp = (UChar*)malloc(sizeof(UChar)*(pttrnLen)); for (int i = 0; i < pttrnLen; i++) { temp[i] = src[start++]; } pttrn = temp; /* store word in pttrn */ ubrk_close(brk); #else /* The first line of the file contains the pattern */ start = 0; for(end = start; ; end += 1) { UChar ch = src[end]; if (ch == 0x000A || ch == 0x000D || ch == 0x2028) { break; } } pttrnLen = end - start; UChar* temp = (UChar*)malloc(sizeof(UChar)*(pttrnLen)); for (int i = 0; i < pttrnLen; i++) { temp[i] = src[start++]; } pttrn = temp; /* store word in pttrn */ #endif #ifdef TEST_BOYER_MOORE_SEARCH UnicodeString patternString(pttrn, pttrnLen); UCollator *coll = ucol_open(locale, &status); CollData *data = CollData::open(coll, status); targetString = new UnicodeString(src, srcLen); bms = new BoyerMooreSearch(data, patternString, targetString, status); #else /* Create the StringSearch object to be use in performance test. */ srch = usearch_open(pttrn, pttrnLen, src, srcLen, locale, NULL, &status); #endif if(U_FAILURE(status)){ fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n", u_errorName(status)); return; } }