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