Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: Source/WebCore/inspector/ContentSearchUtils.cpp

Issue 8371003: Merge 97851 - Web Inspector: Enable caseSensitive search / Regex support in advanced search. (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/912/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/WebCore/inspector/ContentSearchUtils.h ('k') | Source/WebCore/inspector/Inspector.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 static PassRefPtr<InspectorObject> buildObjectForSearchMatch(int lineNumber, Str ing lineContent) 91 static PassRefPtr<InspectorObject> buildObjectForSearchMatch(int lineNumber, Str ing lineContent)
92 { 92 {
93 RefPtr<InspectorObject> result = InspectorObject::create(); 93 RefPtr<InspectorObject> result = InspectorObject::create();
94 result->setNumber("lineNumber", lineNumber); 94 result->setNumber("lineNumber", lineNumber);
95 result->setString("lineContent", lineContent); 95 result->setString("lineContent", lineContent);
96 96
97 return result; 97 return result;
98 } 98 }
99 99
100 RegularExpression createSearchRegex(const String& text, bool caseSensitive, bool isRegex) 100 RegularExpression createSearchRegex(const String& query, bool caseSensitive, boo l isRegex)
101 { 101 {
102 String regexSource = isRegex ? text : createSearchRegexSource(text); 102 String regexSource = isRegex ? query : createSearchRegexSource(query);
103 return RegularExpression(regexSource, caseSensitive ? TextCaseSensitive : Te xtCaseInsensitive); 103 return RegularExpression(regexSource, caseSensitive ? TextCaseSensitive : Te xtCaseInsensitive);
104 } 104 }
105 105
106 int countRegularExpressionMatches(const RegularExpression& regex, const String& content) 106 int countRegularExpressionMatches(const RegularExpression& regex, const String& content)
107 { 107 {
108 int result = 0; 108 int result = 0;
109 int position; 109 int position;
110 unsigned start = 0; 110 unsigned start = 0;
111 int matchLength; 111 int matchLength;
112 while ((position = regex.match(content, start, &matchLength)) != -1) { 112 while ((position = regex.match(content, start, &matchLength)) != -1) {
113 if (start >= content.length()) 113 if (start >= content.length())
114 break; 114 break;
115 if (matchLength > 0) 115 if (matchLength > 0)
116 ++result; 116 ++result;
117 start = position + 1; 117 start = position + 1;
118 } 118 }
119 return result; 119 return result;
120 } 120 }
121 121
122 PassRefPtr<InspectorArray> searchInTextByLines(const String& query, const String & text) 122 PassRefPtr<InspectorArray> searchInTextByLines(const String& text, const String& query, const bool caseSensitive, const bool isRegex)
123 { 123 {
124 RefPtr<InspectorArray> result = InspectorArray::create(); 124 RefPtr<InspectorArray> result = InspectorArray::create();
125 125
126 RegularExpression regex = ContentSearchUtils::createSearchRegex(query, false , false); 126 RegularExpression regex = ContentSearchUtils::createSearchRegex(query, caseS ensitive, isRegex);
127 Vector<pair<int, String> > matches = getRegularExpressionMatchesByLines(rege x, text); 127 Vector<pair<int, String> > matches = getRegularExpressionMatchesByLines(rege x, text);
128 128
129 for (Vector<pair<int, String> >::const_iterator it = matches.begin(); it != matches.end(); ++it) 129 for (Vector<pair<int, String> >::const_iterator it = matches.begin(); it != matches.end(); ++it)
130 result->pushValue(buildObjectForSearchMatch(it->first, it->second)); 130 result->pushValue(buildObjectForSearchMatch(it->first, it->second));
131 131
132 return result; 132 return result;
133 } 133 }
134 134
135 } // namespace ContentSearchUtils 135 } // namespace ContentSearchUtils
136 } // namespace WebCore 136 } // namespace WebCore
137 137
138 #endif // ENABLE(INSPECTOR) 138 #endif // ENABLE(INSPECTOR)
OLDNEW
« no previous file with comments | « Source/WebCore/inspector/ContentSearchUtils.h ('k') | Source/WebCore/inspector/Inspector.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698