OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/android/email_detector.h" | 5 #include "content/renderer/android/email_detector.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "content/public/renderer/android_content_detection_prefixes.h" | 11 #include "content/public/renderer/android_content_detection_prefixes.h" |
11 #include "net/base/escape.h" | 12 #include "net/base/escape.h" |
12 #include "third_party/icu/source/i18n/unicode/regex.h" | 13 #include "third_party/icu/source/i18n/unicode/regex.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // Maximum length of an email address. | 17 // Maximum length of an email address. |
17 const size_t kMaximumEmailLength = 254; | 18 const size_t kMaximumEmailLength = 254; |
18 | 19 |
(...skipping 26 matching lines...) Expand all Loading... |
45 | 46 |
46 bool EmailDetector::FindContent(const base::string16::const_iterator& begin, | 47 bool EmailDetector::FindContent(const base::string16::const_iterator& begin, |
47 const base::string16::const_iterator& end, | 48 const base::string16::const_iterator& end, |
48 size_t* start_pos, | 49 size_t* start_pos, |
49 size_t* end_pos, | 50 size_t* end_pos, |
50 std::string* content_text) { | 51 std::string* content_text) { |
51 base::string16 utf16_input = base::string16(begin, end); | 52 base::string16 utf16_input = base::string16(begin, end); |
52 icu::UnicodeString pattern(kEmailRegex); | 53 icu::UnicodeString pattern(kEmailRegex); |
53 icu::UnicodeString input(utf16_input.data(), utf16_input.length()); | 54 icu::UnicodeString input(utf16_input.data(), utf16_input.length()); |
54 UErrorCode status = U_ZERO_ERROR; | 55 UErrorCode status = U_ZERO_ERROR; |
55 scoped_ptr<icu::RegexMatcher> matcher( | 56 std::unique_ptr<icu::RegexMatcher> matcher( |
56 new icu::RegexMatcher(pattern, | 57 new icu::RegexMatcher(pattern, input, UREGEX_CASE_INSENSITIVE, status)); |
57 input, | |
58 UREGEX_CASE_INSENSITIVE, | |
59 status)); | |
60 if (matcher->find()) { | 58 if (matcher->find()) { |
61 *start_pos = matcher->start(status); | 59 *start_pos = matcher->start(status); |
62 DCHECK(U_SUCCESS(status)); | 60 DCHECK(U_SUCCESS(status)); |
63 *end_pos = matcher->end(status); | 61 *end_pos = matcher->end(status); |
64 DCHECK(U_SUCCESS(status)); | 62 DCHECK(U_SUCCESS(status)); |
65 icu::UnicodeString content_ustr(matcher->group(status)); | 63 icu::UnicodeString content_ustr(matcher->group(status)); |
66 DCHECK(U_SUCCESS(status)); | 64 DCHECK(U_SUCCESS(status)); |
67 base::UTF16ToUTF8(content_ustr.getBuffer(), content_ustr.length(), | 65 base::UTF16ToUTF8(content_ustr.getBuffer(), content_ustr.length(), |
68 content_text); | 66 content_text); |
69 return true; | 67 return true; |
70 } | 68 } |
71 | 69 |
72 return false; | 70 return false; |
73 } | 71 } |
74 | 72 |
75 } // namespace content | 73 } // namespace content |
OLD | NEW |