| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 result.append("\\"); | 55 result.append("\\"); |
| 56 result.append(characters[i]); | 56 result.append(characters[i]); |
| 57 } | 57 } |
| 58 | 58 |
| 59 return result; | 59 return result; |
| 60 } | 60 } |
| 61 | 61 |
| 62 static Vector<pair<int, String> > getRegularExpressionMatchesByLines(const Regul
arExpression& regex, const String& text) | 62 static Vector<pair<int, String> > getRegularExpressionMatchesByLines(const Regul
arExpression& regex, const String& text) |
| 63 { | 63 { |
| 64 Vector<pair<int, String> > result; | 64 Vector<pair<int, String> > result; |
| 65 if (text.isEmpty()) |
| 66 return result; |
| 65 | 67 |
| 66 int lineNumber = 0; | 68 int lineNumber = 0; |
| 67 unsigned start = 0; | 69 unsigned start = 0; |
| 68 while (start < text.length()) { | 70 while (start < text.length()) { |
| 69 size_t lineEnd = text.find('\n', start); | 71 size_t lineEnd = text.find('\n', start); |
| 70 if (lineEnd == notFound) | 72 if (lineEnd == notFound) |
| 71 lineEnd = text.length(); | 73 lineEnd = text.length(); |
| 72 else | 74 else |
| 73 lineEnd++; | 75 lineEnd++; |
| 74 | 76 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 98 } | 100 } |
| 99 | 101 |
| 100 RegularExpression createSearchRegex(const String& query, bool caseSensitive, boo
l isRegex) | 102 RegularExpression createSearchRegex(const String& query, bool caseSensitive, boo
l isRegex) |
| 101 { | 103 { |
| 102 String regexSource = isRegex ? query : createSearchRegexSource(query); | 104 String regexSource = isRegex ? query : createSearchRegexSource(query); |
| 103 return RegularExpression(regexSource, caseSensitive ? TextCaseSensitive : Te
xtCaseInsensitive); | 105 return RegularExpression(regexSource, caseSensitive ? TextCaseSensitive : Te
xtCaseInsensitive); |
| 104 } | 106 } |
| 105 | 107 |
| 106 int countRegularExpressionMatches(const RegularExpression& regex, const String&
content) | 108 int countRegularExpressionMatches(const RegularExpression& regex, const String&
content) |
| 107 { | 109 { |
| 110 if (content.isEmpty()) |
| 111 return 0; |
| 112 |
| 108 int result = 0; | 113 int result = 0; |
| 109 int position; | 114 int position; |
| 110 unsigned start = 0; | 115 unsigned start = 0; |
| 111 int matchLength; | 116 int matchLength; |
| 112 while ((position = regex.match(content, start, &matchLength)) != -1) { | 117 while ((position = regex.match(content, start, &matchLength)) != -1) { |
| 113 if (start >= content.length()) | 118 if (start >= content.length()) |
| 114 break; | 119 break; |
| 115 if (matchLength > 0) | 120 if (matchLength > 0) |
| 116 ++result; | 121 ++result; |
| 117 start = position + 1; | 122 start = position + 1; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 129 for (Vector<pair<int, String> >::const_iterator it = matches.begin(); it !=
matches.end(); ++it) | 134 for (Vector<pair<int, String> >::const_iterator it = matches.begin(); it !=
matches.end(); ++it) |
| 130 result->pushValue(buildObjectForSearchMatch(it->first, it->second)); | 135 result->pushValue(buildObjectForSearchMatch(it->first, it->second)); |
| 131 | 136 |
| 132 return result; | 137 return result; |
| 133 } | 138 } |
| 134 | 139 |
| 135 } // namespace ContentSearchUtils | 140 } // namespace ContentSearchUtils |
| 136 } // namespace WebCore | 141 } // namespace WebCore |
| 137 | 142 |
| 138 #endif // ENABLE(INSPECTOR) | 143 #endif // ENABLE(INSPECTOR) |
| OLD | NEW |