static String findMagicComment(const String& content, const String& name, MagicCommentType commentType, bool* deprecated = 0) { ASSERT(name.find("=") == notFound); if (deprecated) *deprecated = false; String pattern; String deprecatedPattern; switch (commentType) { case JavaScriptMagicComment: pattern = "//#[\040\t]" + createSearchRegexSource(name) + "=[\040\t]*([^\\s\'\"]*)[\040\t]*$"; deprecatedPattern = "//@[\040\t]" + createSearchRegexSource(name) + "=[\040\t]*([^\\s\'\"]*)[\040\t]*$"; break; case CSSMagicComment: pattern = "/\\*#[\040\t]" + createSearchRegexSource(name) + "=[\040\t]*([^\\s]*)[\040\t]*\\*/[\040\t]*$"; deprecatedPattern = "/\\*@[\040\t]" + createSearchRegexSource(name) + "=[\040\t]*([^\\s]*)[\040\t]*\\*/[\040\t]*$"; break; default: ASSERT_NOT_REACHED(); return String(); } RegularExpression regex(pattern, TextCaseSensitive, MultilineEnabled); RegularExpression deprecatedRegex(deprecatedPattern, TextCaseSensitive, MultilineEnabled); int matchLength; int offset = regex.match(content, 0, &matchLength); if (offset == -1) { offset = deprecatedRegex.match(content, 0, &matchLength); if (offset != -1 && deprecated) *deprecated = true; } if (offset == -1) return String(); String match = content.substring(offset, matchLength); size_t separator = match.find("="); ASSERT(separator != notFound); match = match.substring(separator + 1); switch (commentType) { case JavaScriptMagicComment: return match.stripWhiteSpace(); case CSSMagicComment: { size_t lastStarIndex = match.reverseFind('*'); ASSERT(lastStarIndex != notFound); return match.substring(0, lastStarIndex).stripWhiteSpace(); } default: ASSERT_NOT_REACHED(); return String(); } }
static String findMagicComment(const String& content, const String& name) { ASSERT(name.find("=") == notFound); String pattern = "//@[\040\t]" + createSearchRegexSource(name) + "=[\040\t]*[^\\s\'\"]*[\040\t]*$"; RegularExpression regex(pattern, TextCaseSensitive, MultilineEnabled); int matchLength; int offset = regex.match(content, 0, &matchLength); if (offset == -1) return String(); String match = content.substring(offset, matchLength); size_t separator = match.find("="); ASSERT(separator != notFound); return match.substring(separator + 1).stripWhiteSpace(); }
void InspectorPageAgent::searchInResources(ErrorString*, const String& text, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<InspectorArray>* object) { RefPtr<InspectorArray> result = InspectorArray::create(); bool isRegex = optionalIsRegex ? *optionalIsRegex : false; String regexSource = isRegex ? text : createSearchRegexSource(text); bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false; RegularExpression regex(regexSource, caseSensitive ? TextCaseSensitive : TextCaseInsensitive); for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext(m_page->mainFrame())) { String content; bool base64Encoded; Vector<CachedResource*> allResources = cachedResourcesForFrame(frame); for (Vector<CachedResource*>::const_iterator it = allResources.begin(); it != allResources.end(); ++it) { CachedResource* cachedResource = *it; switch (InspectorPageAgent::cachedResourceType(*cachedResource)) { case InspectorPageAgent::StylesheetResource: case InspectorPageAgent::ScriptResource: if (cachedResourceContent(cachedResource, &content, &base64Encoded)) { ASSERT(!base64Encoded); int matchesCount = countRegularExpressionMatches(regex, content); if (matchesCount) result->pushValue(buildObjectForSearchMatch(frameId(frame), cachedResource->url(), matchesCount)); } break; default: break; } } if (mainResourceContent(frame, false, &content)) { int matchesCount = countRegularExpressionMatches(regex, content); if (matchesCount) result->pushValue(buildObjectForSearchMatch(frameId(frame), frame->document()->url(), matchesCount)); } } *object = result; }
RegularExpression createSearchRegex(const String& query, bool caseSensitive, bool isRegex) { String regexSource = isRegex ? query : createSearchRegexSource(query); return RegularExpression(regexSource, caseSensitive ? TextCaseSensitive : TextCaseInsensitive); }
PassOwnPtr<ScriptRegexp> createSearchRegex(const String& query, bool caseSensitive, bool isRegex) { String regexSource = isRegex ? query : createSearchRegexSource(query); return adoptPtr(new ScriptRegexp(regexSource, caseSensitive ? TextCaseSensitive : TextCaseInsensitive)); }
PassOwnPtr<RegularExpression> createSearchRegex(const String& query, bool caseSensitive, bool isRegex) { String regexSource = isRegex ? query : createSearchRegexSource(query); return adoptPtr(new RegularExpression(regexSource, caseSensitive ? TextCaseSensitive : TextCaseInsensitive)); }
RegularExpression createSearchRegex(const String& query, bool caseSensitive, bool isRegex) { return RegularExpression { isRegex ? query : createSearchRegexSource(query), caseSensitive ? TextCaseSensitive : TextCaseInsensitive }; }