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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 for (unsigned i = 0; i < text.length(); i++) { | 50 for (unsigned i = 0; i < text.length(); i++) { |
51 if (specials.find(text[i]) != kNotFound) | 51 if (specials.find(text[i]) != kNotFound) |
52 result.append('\\'); | 52 result.append('\\'); |
53 result.append(text[i]); | 53 result.append(text[i]); |
54 } | 54 } |
55 | 55 |
56 return result.toString(); | 56 return result.toString(); |
57 } | 57 } |
58 | 58 |
59 static Vector<pair<int, String> > getScriptRegexpMatchesByLines(const ScriptRege
xp* regex, const String& text) | 59 static Vector<pair<int, String>> getScriptRegexpMatchesByLines(const ScriptRegex
p* regex, const String& text) |
60 { | 60 { |
61 Vector<pair<int, String> > result; | 61 Vector<pair<int, String>> result; |
62 if (text.isEmpty()) | 62 if (text.isEmpty()) |
63 return result; | 63 return result; |
64 | 64 |
65 OwnPtr<Vector<unsigned> > endings(lineEndings(text)); | 65 OwnPtr<Vector<unsigned>> endings(lineEndings(text)); |
66 unsigned size = endings->size(); | 66 unsigned size = endings->size(); |
67 unsigned start = 0; | 67 unsigned start = 0; |
68 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { | 68 for (unsigned lineNumber = 0; lineNumber < size; ++lineNumber) { |
69 unsigned lineEnd = endings->at(lineNumber); | 69 unsigned lineEnd = endings->at(lineNumber); |
70 String line = text.substring(start, lineEnd - start); | 70 String line = text.substring(start, lineEnd - start); |
71 if (line.endsWith('\r')) | 71 if (line.endsWith('\r')) |
72 line = line.left(line.length() - 1); | 72 line = line.left(line.length() - 1); |
73 | 73 |
74 int matchLength; | 74 int matchLength; |
75 if (regex->match(line, 0, &matchLength) != -1) | 75 if (regex->match(line, 0, &matchLength) != -1) |
(...skipping 11 matching lines...) Expand all Loading... |
87 .setLineContent(lineContent) | 87 .setLineContent(lineContent) |
88 .release(); | 88 .release(); |
89 } | 89 } |
90 | 90 |
91 PassOwnPtr<ScriptRegexp> createSearchRegex(const String& query, bool caseSensiti
ve, bool isRegex) | 91 PassOwnPtr<ScriptRegexp> createSearchRegex(const String& query, bool caseSensiti
ve, bool isRegex) |
92 { | 92 { |
93 String regexSource = isRegex ? query : createSearchRegexSource(query); | 93 String regexSource = isRegex ? query : createSearchRegexSource(query); |
94 return adoptPtr(new ScriptRegexp(regexSource, caseSensitive ? TextCaseSensit
ive : TextCaseInsensitive)); | 94 return adoptPtr(new ScriptRegexp(regexSource, caseSensitive ? TextCaseSensit
ive : TextCaseInsensitive)); |
95 } | 95 } |
96 | 96 |
97 PassRefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> > searchInTextByLi
nes(const String& text, const String& query, const bool caseSensitive, const boo
l isRegex) | 97 PassRefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch>> searchInTextByLin
es(const String& text, const String& query, const bool caseSensitive, const bool
isRegex) |
98 { | 98 { |
99 RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> > result = TypeBui
lder::Array<TypeBuilder::Page::SearchMatch>::create(); | 99 RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch>> result = TypeBuil
der::Array<TypeBuilder::Page::SearchMatch>::create(); |
100 | 100 |
101 OwnPtr<ScriptRegexp> regex = ContentSearchUtils::createSearchRegex(query, ca
seSensitive, isRegex); | 101 OwnPtr<ScriptRegexp> regex = ContentSearchUtils::createSearchRegex(query, ca
seSensitive, isRegex); |
102 Vector<pair<int, String> > matches = getScriptRegexpMatchesByLines(regex.get
(), text); | 102 Vector<pair<int, String>> matches = getScriptRegexpMatchesByLines(regex.get(
), text); |
103 | 103 |
104 for (const auto& match : matches) | 104 for (const auto& match : matches) |
105 result->addItem(buildObjectForSearchMatch(match.first, match.second)); | 105 result->addItem(buildObjectForSearchMatch(match.first, match.second)); |
106 | 106 |
107 return result; | 107 return result; |
108 } | 108 } |
109 | 109 |
110 static String findMagicComment(const String& content, const String& name, MagicC
ommentType commentType, bool* deprecated = 0) | 110 static String findMagicComment(const String& content, const String& name, MagicC
ommentType commentType, bool* deprecated = 0) |
111 { | 111 { |
112 ASSERT(name.find("=") == kNotFound); | 112 ASSERT(name.find("=") == kNotFound); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 179 } |
180 | 180 |
181 String findSourceMapURL(const String& content, MagicCommentType commentType, boo
l* deprecated) | 181 String findSourceMapURL(const String& content, MagicCommentType commentType, boo
l* deprecated) |
182 { | 182 { |
183 return findMagicComment(content, "sourceMappingURL", commentType, deprecated
); | 183 return findMagicComment(content, "sourceMappingURL", commentType, deprecated
); |
184 } | 184 } |
185 | 185 |
186 } // namespace ContentSearchUtils | 186 } // namespace ContentSearchUtils |
187 } // namespace blink | 187 } // namespace blink |
188 | 188 |
OLD | NEW |