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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 156 |
157 OwnPtr<RegularExpression> regex = ContentSearchUtils::createSearchRegex(quer
y, caseSensitive, isRegex); | 157 OwnPtr<RegularExpression> regex = ContentSearchUtils::createSearchRegex(quer
y, caseSensitive, isRegex); |
158 Vector<pair<int, String> > matches = getRegularExpressionMatchesByLines(rege
x.get(), text); | 158 Vector<pair<int, String> > matches = getRegularExpressionMatchesByLines(rege
x.get(), text); |
159 | 159 |
160 for (Vector<pair<int, String> >::const_iterator it = matches.begin(); it !=
matches.end(); ++it) | 160 for (Vector<pair<int, String> >::const_iterator it = matches.begin(); it !=
matches.end(); ++it) |
161 result->addItem(buildObjectForSearchMatch(it->first, it->second)); | 161 result->addItem(buildObjectForSearchMatch(it->first, it->second)); |
162 | 162 |
163 return result; | 163 return result; |
164 } | 164 } |
165 | 165 |
166 String findMagicComment(const String& content, const String& name, MagicCommentT
ype commentType) | 166 static String findMagicComment(const String& content, const String& name, MagicC
ommentType commentType, bool* deprecated = 0) |
167 { | 167 { |
168 ASSERT(name.find("=") == notFound); | 168 ASSERT(name.find("=") == notFound); |
| 169 if (deprecated) |
| 170 *deprecated = false; |
169 String pattern; | 171 String pattern; |
| 172 String deprecatedPattern; |
170 switch (commentType) { | 173 switch (commentType) { |
171 case JavaScriptMagicComment: | 174 case JavaScriptMagicComment: |
172 pattern= "//@[\040\t]" + createSearchRegexSource(name) + "=[\040\t]*([^\
\s\'\"]*)[\040\t]*$"; | 175 pattern = "//#[\040\t]" + createSearchRegexSource(name) + "=[\040\t]*([^
\\s\'\"]*)[\040\t]*$"; |
| 176 deprecatedPattern = "//@[\040\t]" + createSearchRegexSource(name) + "=[\
040\t]*([^\\s\'\"]*)[\040\t]*$"; |
173 break; | 177 break; |
174 case CSSMagicComment: | 178 case CSSMagicComment: |
175 pattern= "/\\*@[\040\t]" + createSearchRegexSource(name) + "=[\040\t]*([
^\\s]*)[\040\t]*\\*/[\040\t]*$"; | 179 pattern = "/\\*#[\040\t]" + createSearchRegexSource(name) + "=[\040\t]*(
[^\\s]*)[\040\t]*\\*/[\040\t]*$"; |
| 180 deprecatedPattern = "/\\*@[\040\t]" + createSearchRegexSource(name) + "=
[\040\t]*([^\\s]*)[\040\t]*\\*/[\040\t]*$"; |
176 break; | 181 break; |
177 default: | 182 default: |
178 ASSERT_NOT_REACHED(); | 183 ASSERT_NOT_REACHED(); |
179 return String(); | 184 return String(); |
180 } | 185 } |
181 RegularExpression regex(pattern, TextCaseSensitive, MultilineEnabled); | 186 RegularExpression regex(pattern, TextCaseSensitive, MultilineEnabled); |
| 187 RegularExpression deprecatedRegex(deprecatedPattern, TextCaseSensitive, Mult
ilineEnabled); |
182 | 188 |
183 int matchLength; | 189 int matchLength; |
184 int offset = regex.match(content, 0, &matchLength); | 190 int offset = regex.match(content, 0, &matchLength); |
| 191 if (offset == -1) { |
| 192 offset = deprecatedRegex.match(content, 0, &matchLength); |
| 193 if (offset != -1 && deprecated) |
| 194 *deprecated = true; |
| 195 } |
185 if (offset == -1) | 196 if (offset == -1) |
186 return String(); | 197 return String(); |
187 | 198 |
188 String match = content.substring(offset, matchLength); | 199 String match = content.substring(offset, matchLength); |
189 size_t separator = match.find("="); | 200 size_t separator = match.find("="); |
190 ASSERT(separator != notFound); | 201 ASSERT(separator != notFound); |
191 match = match.substring(separator + 1); | 202 match = match.substring(separator + 1); |
192 | 203 |
193 switch (commentType) { | 204 switch (commentType) { |
194 case JavaScriptMagicComment: | 205 case JavaScriptMagicComment: |
195 return match.stripWhiteSpace(); | 206 return match.stripWhiteSpace(); |
196 case CSSMagicComment: { | 207 case CSSMagicComment: { |
197 size_t lastStarIndex = match.reverseFind('*'); | 208 size_t lastStarIndex = match.reverseFind('*'); |
198 ASSERT(lastStarIndex != notFound); | 209 ASSERT(lastStarIndex != notFound); |
199 return match.substring(0, lastStarIndex).stripWhiteSpace(); | 210 return match.substring(0, lastStarIndex).stripWhiteSpace(); |
200 } | 211 } |
201 default: | 212 default: |
202 ASSERT_NOT_REACHED(); | 213 ASSERT_NOT_REACHED(); |
203 return String(); | 214 return String(); |
204 } | 215 } |
205 } | 216 } |
206 | 217 |
207 String findSourceURL(const String& content, MagicCommentType commentType) | 218 String findSourceURL(const String& content, MagicCommentType commentType, bool*
deprecated) |
208 { | 219 { |
209 return findMagicComment(content, "sourceURL", commentType); | 220 return findMagicComment(content, "sourceURL", commentType, deprecated); |
210 } | 221 } |
211 | 222 |
212 String findSourceMapURL(const String& content, MagicCommentType commentType) | 223 String findSourceMapURL(const String& content, MagicCommentType commentType, boo
l* deprecated) |
213 { | 224 { |
214 return findMagicComment(content, "sourceMappingURL", commentType); | 225 return findMagicComment(content, "sourceMappingURL", commentType, deprecated
); |
215 } | 226 } |
216 | 227 |
217 } // namespace ContentSearchUtils | 228 } // namespace ContentSearchUtils |
218 } // namespace WebCore | 229 } // namespace WebCore |
219 | 230 |
OLD | NEW |