OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * | 10 * |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 .setLineContent(lineContent) | 88 .setLineContent(lineContent) |
89 .release(); | 89 .release(); |
90 } | 90 } |
91 | 91 |
92 PassOwnPtr<ScriptRegexp> createSearchRegex(const String& query, bool caseSensiti
ve, bool isRegex) | 92 PassOwnPtr<ScriptRegexp> createSearchRegex(const String& query, bool caseSensiti
ve, bool isRegex) |
93 { | 93 { |
94 String regexSource = isRegex ? query : createSearchRegexSource(query); | 94 String regexSource = isRegex ? query : createSearchRegexSource(query); |
95 return adoptPtr(new ScriptRegexp(regexSource, caseSensitive ? TextCaseSensit
ive : TextCaseInsensitive)); | 95 return adoptPtr(new ScriptRegexp(regexSource, caseSensitive ? TextCaseSensit
ive : TextCaseInsensitive)); |
96 } | 96 } |
97 | 97 |
98 int countScriptRegexpMatches(const ScriptRegexp* regex, const String& content) | |
99 { | |
100 if (content.isEmpty()) | |
101 return 0; | |
102 | |
103 int result = 0; | |
104 int position; | |
105 unsigned start = 0; | |
106 int matchLength; | |
107 while ((position = regex->match(content, start, &matchLength)) != -1) { | |
108 if (start >= content.length()) | |
109 break; | |
110 if (matchLength > 0) | |
111 ++result; | |
112 start = position + 1; | |
113 } | |
114 return result; | |
115 } | |
116 | |
117 PassRefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> > searchInTextByLi
nes(const String& text, const String& query, const bool caseSensitive, const boo
l isRegex) | 98 PassRefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> > searchInTextByLi
nes(const String& text, const String& query, const bool caseSensitive, const boo
l isRegex) |
118 { | 99 { |
119 RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> > result = TypeBui
lder::Array<TypeBuilder::Page::SearchMatch>::create(); | 100 RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> > result = TypeBui
lder::Array<TypeBuilder::Page::SearchMatch>::create(); |
120 | 101 |
121 OwnPtr<ScriptRegexp> regex = ContentSearchUtils::createSearchRegex(query, ca
seSensitive, isRegex); | 102 OwnPtr<ScriptRegexp> regex = ContentSearchUtils::createSearchRegex(query, ca
seSensitive, isRegex); |
122 Vector<pair<int, String> > matches = getScriptRegexpMatchesByLines(regex.get
(), text); | 103 Vector<pair<int, String> > matches = getScriptRegexpMatchesByLines(regex.get
(), text); |
123 | 104 |
124 for (Vector<pair<int, String> >::const_iterator it = matches.begin(); it !=
matches.end(); ++it) | 105 for (Vector<pair<int, String> >::const_iterator it = matches.begin(); it !=
matches.end(); ++it) |
125 result->addItem(buildObjectForSearchMatch(it->first, it->second)); | 106 result->addItem(buildObjectForSearchMatch(it->first, it->second)); |
126 | 107 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 176 } |
196 | 177 |
197 String findSourceMapURL(const String& content, MagicCommentType commentType, boo
l* deprecated) | 178 String findSourceMapURL(const String& content, MagicCommentType commentType, boo
l* deprecated) |
198 { | 179 { |
199 return findMagicComment(content, "sourceMappingURL", commentType, deprecated
); | 180 return findMagicComment(content, "sourceMappingURL", commentType, deprecated
); |
200 } | 181 } |
201 | 182 |
202 } // namespace ContentSearchUtils | 183 } // namespace ContentSearchUtils |
203 } // namespace WebCore | 184 } // namespace WebCore |
204 | 185 |
OLD | NEW |