void RegularExpression::Private::compile(bool caseSensitive) { const char* errorMessage; regex = jsRegExpCompile(pattern.characters(), pattern.length(), caseSensitive ? JSRegExpDoNotIgnoreCase : JSRegExpIgnoreCase, JSRegExpSingleLine, 0, &errorMessage); if (!regex) LOG_ERROR("RegularExpression: pcre_compile failed with '%s'", errorMessage); }
inline JSRegExp* RegularExpression::Private::compile(const String& pattern, TextCaseSensitivity caseSensitivity) { const char* errorMessage; JSRegExp* regexp = jsRegExpCompile(pattern.characters(), pattern.length(), caseSensitivity == TextCaseSensitive ? JSRegExpDoNotIgnoreCase : JSRegExpIgnoreCase, JSRegExpSingleLine, 0, &errorMessage); if (!regexp) LOG_ERROR("RegularExpression: pcre_compile failed with '%s'", errorMessage); return regexp; }
RegExpImpl(const void* pattern, int len, unsigned flags) : RegExpBase(flags) { const char* errorMessage = NULL; re_ = jsRegExpCompile( static_cast<const uint16_t*>(pattern), len, ignoreCase() ? dart::jscre::JSRegExpIgnoreCase : dart::jscre::JSRegExpDoNotIgnoreCase, multiline() ? dart::jscre::JSRegExpMultiline : dart::jscre::JSRegExpSingleLine, &numSubpatterns_, &errorMessage, malloc, free); }
inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern) : m_pattern(pattern) , m_flagBits(0) , m_regExp(0) , m_constructionError(0) , m_numSubpatterns(0) { #if ENABLE(WREC) m_wrecFunction = CTI::compileRegExp(globalData->machine, pattern, &m_numSubpatterns, &m_constructionError); if (m_wrecFunction) return; // Fall through to non-WREC case. #else UNUSED_PARAM(globalData); #endif m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, &m_numSubpatterns, &m_constructionError); }
inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern, const UString& flags) : m_pattern(pattern) , m_flags(flags) , m_flagBits(0) , m_regExp(0) , m_constructionError(0) , m_numSubpatterns(0) { // NOTE: The global flag is handled on a case-by-case basis by functions like // String::match and RegExpObject::match. if (flags.find('g') != -1) m_flagBits |= Global; // FIXME: Eliminate duplication by adding a way ask a JSRegExp what its flags are? JSRegExpIgnoreCaseOption ignoreCaseOption = JSRegExpDoNotIgnoreCase; if (flags.find('i') != -1) { m_flagBits |= IgnoreCase; ignoreCaseOption = JSRegExpIgnoreCase; } JSRegExpMultilineOption multilineOption = JSRegExpSingleLine; if (flags.find('m') != -1) { m_flagBits |= Multiline; multilineOption = JSRegExpMultiline; } #if ENABLE(WREC) m_wrecFunction = CTI::compileRegExp(globalData->machine, pattern, &m_numSubpatterns, &m_constructionError, (m_flagBits & IgnoreCase), (m_flagBits & Multiline)); if (m_wrecFunction) return; // Fall through to non-WREC case. #else UNUSED_PARAM(globalData); #endif m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); }
int RegExp::match(const UString& s, int startOffset, Vector<int, 32>* ovector) { if (startOffset < 0) startOffset = 0; if (ovector) ovector->clear(); if (startOffset > s.size() || s.isNull()) return -1; #if ENABLE(YARR_JIT) if (!!m_regExpJITCode) { #else if (m_regExpBytecode) { #endif int offsetVectorSize = (m_numSubpatterns + 1) * 3; // FIXME: should be 2 - but adding temporary fallback to pcre. int* offsetVector; Vector<int, 32> nonReturnedOvector; if (ovector) { ovector->resize(offsetVectorSize); offsetVector = ovector->data(); } else { nonReturnedOvector.resize(offsetVectorSize); offsetVector = nonReturnedOvector.data(); } ASSERT(offsetVector); for (int j = 0; j < offsetVectorSize; ++j) offsetVector[j] = -1; #if ENABLE(YARR_JIT) int result = Yarr::executeRegex(m_regExpJITCode, s.data(), startOffset, s.size(), offsetVector, offsetVectorSize); #else int result = Yarr::interpretRegex(m_regExpBytecode.get(), s.data(), startOffset, s.size(), offsetVector); #endif if (result < 0) { #ifndef NDEBUG // TODO: define up a symbol, rather than magic -1 if (result != -1) fprintf(stderr, "jsRegExpExecute failed with result %d\n", result); #endif if (ovector) ovector->clear(); } return result; } return -1; } #else void RegExp::compile(JSGlobalData* globalData) { m_regExp = 0; #if ENABLE(WREC) m_wrecFunction = Generator::compileRegExp(globalData, m_pattern, &m_numSubpatterns, &m_constructionError, m_executablePool, ignoreCase(), multiline()); if (m_wrecFunction || m_constructionError) return; // Fall through to non-WREC case. #else UNUSED_PARAM(globalData); #endif JSRegExpIgnoreCaseOption ignoreCaseOption = ignoreCase() ? JSRegExpIgnoreCase : JSRegExpDoNotIgnoreCase; JSRegExpMultilineOption multilineOption = multiline() ? JSRegExpMultiline : JSRegExpSingleLine; m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(m_pattern.data()), m_pattern.size(), ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); }