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

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: macros.h 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
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..3dfeeec505f1cc5b0a149d0d2bc883374ccf6b42 100644
--- a/components/autofill/core/common/autofill_regexes.cc
+++ b/components/autofill/core/common/autofill_regexes.cc
@@ -8,8 +8,7 @@
#include "base/logging.h"
#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 "third_party/re2/re2/re2.h"
namespace {
@@ -19,7 +18,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 std::string& pattern);
private:
AutofillRegexes();
@@ -27,8 +26,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<std::string, scoped_ptr<re2::RE2>> matchers_;
DISALLOW_COPY_AND_ASSIGN(AutofillRegexes);
};
@@ -44,16 +42,11 @@ AutofillRegexes::AutofillRegexes() {
AutofillRegexes::~AutofillRegexes() {
}
-icu::RegexMatcher* AutofillRegexes::GetMatcher(const base::string16& pattern) {
+re2::RE2* AutofillRegexes::GetMatcher(const std::string& pattern) {
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(pattern));
+ DCHECK(matcher->ok());
auto result = matchers_.add(pattern, matcher.Pass());
DCHECK(result.second);
it = result.first;
@@ -65,17 +58,9 @@ icu::RegexMatcher* AutofillRegexes::GetMatcher(const base::string16& pattern) {
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;
+bool MatchesPattern(const std::string& input, const std::string& pattern) {
+ re2::RE2* matcher = AutofillRegexes::GetInstance()->GetMatcher(pattern);
Ilya Sherman 2015/11/19 02:09:00 Please add a TODO to verify whether it's still wor
tfarina 2015/11/20 19:03:37 Done.
+ return re2::RE2::FullMatch(input, *matcher);
Ilya Sherman 2015/11/19 02:09:00 Do the tests pass with this change? I would have
tfarina 2015/11/20 19:03:37 Now they do. Sorry for not getting to test this lo
}
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698