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

Unified Diff: components/autofill/core/common/autofill_regexes.cc

Issue 1453193002: autofill: switch autofill_regexes to RE2 library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: deps Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/core/common/DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/common/autofill_regexes.cc
diff --git a/components/autofill/core/common/autofill_regexes.cc b/components/autofill/core/common/autofill_regexes.cc
index cdea63cb5c83c1ab3bca8008a6fa2fe0c44b7a73..f5e502ec61f5410be1eaa38717986799f04c4b0e 100644
--- a/components/autofill/core/common/autofill_regexes.cc
+++ b/components/autofill/core/common/autofill_regexes.cc
@@ -9,7 +9,8 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/strings/string16.h"
-#include "third_party/icu/source/i18n/unicode/regex.h"
+#include "base/strings/utf_string_conversions.h"
+#include "third_party/re2/re2/re2.h"
namespace {
@@ -19,7 +20,7 @@ class AutofillRegexes {
static AutofillRegexes* GetInstance();
// Returns the compiled regex matcher corresponding to |pattern|.
- icu::RegexMatcher* GetMatcher(const base::string16& pattern);
+ re2::RE2* GetMatcher(const base::string16& pattern);
private:
AutofillRegexes();
@@ -27,8 +28,7 @@ class AutofillRegexes {
friend struct base::DefaultSingletonTraits<AutofillRegexes>;
// Maps patterns to their corresponding regex matchers.
- base::ScopedPtrHashMap<base::string16, scoped_ptr<icu::RegexMatcher>>
- matchers_;
+ base::ScopedPtrHashMap<base::string16, scoped_ptr<re2::RE2>> matchers_;
DISALLOW_COPY_AND_ASSIGN(AutofillRegexes);
};
@@ -44,16 +44,10 @@ AutofillRegexes::AutofillRegexes() {
AutofillRegexes::~AutofillRegexes() {
}
-icu::RegexMatcher* AutofillRegexes::GetMatcher(const base::string16& pattern) {
+re2::RE2* AutofillRegexes::GetMatcher(const base::string16& pattern) {
vabr (Chromium) 2015/11/18 09:26:36 Tracing this to the callsites, it appears that we
tfarina 2015/11/18 18:03:10 I don't think that was a good suggestion. That req
Ilya Sherman 2015/11/19 02:08:59 I think you might have misunderstood Václav's sugg
vabr (Chromium) 2015/11/19 08:09:04 @tfarina -- sorry that I was unclear; I really mea
tfarina 2015/11/20 19:03:37 Ilya, can I do this API change in a follow up? I d
Ilya Sherman 2015/11/20 22:27:59 I'd prefer that you make the change as part of thi
auto it = matchers_.find(pattern);
if (it == matchers_.end()) {
- const icu::UnicodeString icu_pattern(pattern.data(), pattern.length());
-
- UErrorCode status = U_ZERO_ERROR;
- scoped_ptr<icu::RegexMatcher> matcher(
- new icu::RegexMatcher(icu_pattern, UREGEX_CASE_INSENSITIVE, status));
- DCHECK(U_SUCCESS(status));
-
+ scoped_ptr<re2::RE2> matcher(new re2::RE2(base::UTF16ToUTF8(pattern)));
auto result = matchers_.add(pattern, matcher.Pass());
DCHECK(result.second);
it = result.first;
@@ -67,15 +61,8 @@ namespace autofill {
bool MatchesPattern(const base::string16& input,
const base::string16& pattern) {
- icu::RegexMatcher* matcher =
- AutofillRegexes::GetInstance()->GetMatcher(pattern);
- icu::UnicodeString icu_input(input.data(), input.length());
- matcher->reset(icu_input);
-
- UErrorCode status = U_ZERO_ERROR;
- UBool match = matcher->find(0, status);
- DCHECK(U_SUCCESS(status));
- return match == TRUE;
+ re2::RE2* matcher = AutofillRegexes::GetInstance()->GetMatcher(pattern);
+ return matcher->ok();
Ilya Sherman 2015/11/18 06:48:50 Hmm, it looks like you aren't using the |input| at
vabr (Chromium) 2015/11/18 09:26:36 +1, ok() only checks if the matcher was created wi
tfarina 2015/11/18 18:03:10 Done.
}
} // namespace autofill
« no previous file with comments | « components/autofill/core/common/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698