| 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 15 matching lines...) Expand all Loading... |
| 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 | 30 |
| 31 #include "core/inspector/ContentSearchUtils.h" | 31 #include "core/inspector/ContentSearchUtils.h" |
| 32 | 32 |
| 33 #include "bindings/v8/ScriptRegexp.h" | 33 #include "bindings/v8/ScriptRegexp.h" |
| 34 #include "wtf/text/StringBuilder.h" | 34 #include "wtf/text/StringBuilder.h" |
| 35 | 35 |
| 36 using namespace std; | |
| 37 | |
| 38 namespace WebCore { | 36 namespace WebCore { |
| 39 namespace ContentSearchUtils { | 37 namespace ContentSearchUtils { |
| 40 | 38 |
| 41 namespace { | 39 namespace { |
| 42 // This should be kept the same as the one in front-end/utilities.js | 40 // This should be kept the same as the one in front-end/utilities.js |
| 43 static const char regexSpecialCharacters[] = "[](){}+-*.,?\\^$|"; | 41 static const char regexSpecialCharacters[] = "[](){}+-*.,?\\^$|"; |
| 44 } | 42 } |
| 45 | 43 |
| 46 static String createSearchRegexSource(const String& text) | 44 static String createSearchRegexSource(const String& text) |
| 47 { | 45 { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 108 |
| 111 static String findMagicComment(const String& content, const String& name, MagicC
ommentType commentType, bool* deprecated = 0) | 109 static String findMagicComment(const String& content, const String& name, MagicC
ommentType commentType, bool* deprecated = 0) |
| 112 { | 110 { |
| 113 ASSERT(name.find("=") == kNotFound); | 111 ASSERT(name.find("=") == kNotFound); |
| 114 if (deprecated) | 112 if (deprecated) |
| 115 *deprecated = false; | 113 *deprecated = false; |
| 116 | 114 |
| 117 unsigned length = content.length(); | 115 unsigned length = content.length(); |
| 118 unsigned nameLength = name.length(); | 116 unsigned nameLength = name.length(); |
| 119 | 117 |
| 120 size_t pos = length; | 118 std::size_t pos = length; |
| 121 size_t equalSignPos = 0; | 119 std::size_t equalSignPos = 0; |
| 122 size_t closingCommentPos = 0; | 120 std::size_t closingCommentPos = 0; |
| 123 while (true) { | 121 while (true) { |
| 124 pos = content.reverseFind(name, pos); | 122 pos = content.reverseFind(name, pos); |
| 125 if (pos == kNotFound) | 123 if (pos == kNotFound) |
| 126 return String(); | 124 return String(); |
| 127 | 125 |
| 128 // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name
. | 126 // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name
. |
| 129 if (pos < 4) | 127 if (pos < 4) |
| 130 return String(); | 128 return String(); |
| 131 pos -= 4; | 129 pos -= 4; |
| 132 if (content[pos] != '/') | 130 if (content[pos] != '/') |
| (...skipping 15 matching lines...) Expand all Loading... |
| 148 } | 146 } |
| 149 | 147 |
| 150 break; | 148 break; |
| 151 } | 149 } |
| 152 | 150 |
| 153 if (deprecated && content[pos + 2] == '@') | 151 if (deprecated && content[pos + 2] == '@') |
| 154 *deprecated = true; | 152 *deprecated = true; |
| 155 | 153 |
| 156 ASSERT(equalSignPos); | 154 ASSERT(equalSignPos); |
| 157 ASSERT(commentType != CSSMagicComment || closingCommentPos); | 155 ASSERT(commentType != CSSMagicComment || closingCommentPos); |
| 158 size_t urlPos = equalSignPos + 1; | 156 std::size_t urlPos = equalSignPos + 1; |
| 159 String match = commentType == CSSMagicComment | 157 String match = commentType == CSSMagicComment |
| 160 ? content.substring(urlPos, closingCommentPos - urlPos) | 158 ? content.substring(urlPos, closingCommentPos - urlPos) |
| 161 : content.substring(urlPos); | 159 : content.substring(urlPos); |
| 162 | 160 |
| 163 size_t newLine = match.find("\n"); | 161 std::size_t newLine = match.find("\n"); |
| 164 if (newLine != kNotFound) | 162 if (newLine != kNotFound) |
| 165 match = match.substring(0, newLine); | 163 match = match.substring(0, newLine); |
| 166 match = match.stripWhiteSpace(); | 164 match = match.stripWhiteSpace(); |
| 167 | 165 |
| 168 String disallowedChars("\"' \t"); | 166 String disallowedChars("\"' \t"); |
| 169 for (unsigned i = 0; i < match.length(); ++i) { | 167 for (unsigned i = 0; i < match.length(); ++i) { |
| 170 if (disallowedChars.find(match[i]) != kNotFound) | 168 if (disallowedChars.find(match[i]) != kNotFound) |
| 171 return ""; | 169 return ""; |
| 172 } | 170 } |
| 173 | 171 |
| 174 return match; | 172 return match; |
| 175 } | 173 } |
| 176 | 174 |
| 177 String findSourceURL(const String& content, MagicCommentType commentType, bool*
deprecated) | 175 String findSourceURL(const String& content, MagicCommentType commentType, bool*
deprecated) |
| 178 { | 176 { |
| 179 return findMagicComment(content, "sourceURL", commentType, deprecated); | 177 return findMagicComment(content, "sourceURL", commentType, deprecated); |
| 180 } | 178 } |
| 181 | 179 |
| 182 String findSourceMapURL(const String& content, MagicCommentType commentType, boo
l* deprecated) | 180 String findSourceMapURL(const String& content, MagicCommentType commentType, boo
l* deprecated) |
| 183 { | 181 { |
| 184 return findMagicComment(content, "sourceMappingURL", commentType, deprecated
); | 182 return findMagicComment(content, "sourceMappingURL", commentType, deprecated
); |
| 185 } | 183 } |
| 186 | 184 |
| 187 } // namespace ContentSearchUtils | 185 } // namespace ContentSearchUtils |
| 188 } // namespace WebCore | 186 } // namespace WebCore |
| 189 | 187 |
| OLD | NEW |