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

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

Issue 1518783002: Revert of autofill: switch autofill_regexes to RE2 library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 7f914b9315db44c6c0215ee1de48c668479ba2fb..cdea63cb5c83c1ab3bca8008a6fa2fe0c44b7a73 100644
--- a/components/autofill/core/common/autofill_regexes.cc
+++ b/components/autofill/core/common/autofill_regexes.cc
@@ -8,8 +8,8 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
-#include "base/strings/utf_string_conversions.h"
-#include "third_party/re2/re2/re2.h"
+#include "base/strings/string16.h"
+#include "third_party/icu/source/i18n/unicode/regex.h"
namespace {
@@ -19,7 +19,7 @@
static AutofillRegexes* GetInstance();
// Returns the compiled regex matcher corresponding to |pattern|.
- re2::RE2* GetMatcher(const std::string& pattern);
+ icu::RegexMatcher* GetMatcher(const base::string16& pattern);
private:
AutofillRegexes();
@@ -27,7 +27,8 @@
friend struct base::DefaultSingletonTraits<AutofillRegexes>;
// Maps patterns to their corresponding regex matchers.
- base::ScopedPtrHashMap<std::string, scoped_ptr<re2::RE2>> matchers_;
+ base::ScopedPtrHashMap<base::string16, scoped_ptr<icu::RegexMatcher>>
+ matchers_;
DISALLOW_COPY_AND_ASSIGN(AutofillRegexes);
};
@@ -43,13 +44,16 @@
AutofillRegexes::~AutofillRegexes() {
}
-re2::RE2* AutofillRegexes::GetMatcher(const std::string& pattern) {
+icu::RegexMatcher* AutofillRegexes::GetMatcher(const base::string16& pattern) {
auto it = matchers_.find(pattern);
if (it == matchers_.end()) {
- re2::RE2::Options options;
- options.set_case_sensitive(false);
- scoped_ptr<re2::RE2> matcher(new re2::RE2(pattern, options));
- DCHECK(matcher->ok());
+ 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));
+
auto result = matchers_.add(pattern, matcher.Pass());
DCHECK(result.second);
it = result.first;
@@ -61,12 +65,17 @@
namespace autofill {
-bool MatchesPattern(const base::string16& input, const std::string& pattern) {
- // TODO(isherman): Run performance tests to determine whether caching regex
- // matchers is still useful now that we've switched from ICU to RE2.
- // http://crbug.com/470065
- re2::RE2* matcher = AutofillRegexes::GetInstance()->GetMatcher(pattern);
- return re2::RE2::PartialMatch(base::UTF16ToUTF8(input), *matcher);
+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;
}
} // namespace autofill
« no previous file with comments | « components/autofill/core/common/autofill_regexes.h ('k') | components/autofill/core/common/autofill_regexes_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698