| 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/phone_number_detector.h" | 5 #include "content/renderer/android/phone_number_detector.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 net::EscapeQueryParamValue(content_text, true)); | 54 net::EscapeQueryParamValue(content_text, true)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool PhoneNumberDetector::FindContent( | 57 bool PhoneNumberDetector::FindContent( |
| 58 const base::string16::const_iterator& begin, | 58 const base::string16::const_iterator& begin, |
| 59 const base::string16::const_iterator& end, | 59 const base::string16::const_iterator& end, |
| 60 size_t* start_pos, | 60 size_t* start_pos, |
| 61 size_t* end_pos, | 61 size_t* end_pos, |
| 62 std::string* content_text) { | 62 std::string* content_text) { |
| 63 base::string16 utf16_input = base::string16(begin, end); | 63 base::string16 utf16_input = base::string16(begin, end); |
| 64 std::string utf8_input = UTF16ToUTF8(utf16_input); | 64 std::string utf8_input = base::UTF16ToUTF8(utf16_input); |
| 65 | 65 |
| 66 PhoneNumberMatcher matcher(utf8_input, region_code_); | 66 PhoneNumberMatcher matcher(utf8_input, region_code_); |
| 67 if (matcher.HasNext()) { | 67 if (matcher.HasNext()) { |
| 68 PhoneNumberMatch match; | 68 PhoneNumberMatch match; |
| 69 matcher.Next(&match); | 69 matcher.Next(&match); |
| 70 | 70 |
| 71 PhoneNumberUtil* phone_util = PhoneNumberUtil::GetInstance(); | 71 PhoneNumberUtil* phone_util = PhoneNumberUtil::GetInstance(); |
| 72 phone_util->FormatNumberForMobileDialing(match.number(), region_code_, | 72 phone_util->FormatNumberForMobileDialing(match.number(), region_code_, |
| 73 false, /* with_formatting */ | 73 false, /* with_formatting */ |
| 74 content_text); | 74 content_text); |
| 75 // If the number can't be dialed from the current region, the formatted | 75 // If the number can't be dialed from the current region, the formatted |
| 76 // string will be empty. | 76 // string will be empty. |
| 77 if (content_text->empty()) | 77 if (content_text->empty()) |
| 78 return false; | 78 return false; |
| 79 | 79 |
| 80 // Need to return start_pos and end_pos relative to a UTF16 encoding. | 80 // Need to return start_pos and end_pos relative to a UTF16 encoding. |
| 81 *start_pos = UTF8ToUTF16(utf8_input.substr(0, match.start())).length(); | 81 *start_pos = |
| 82 *end_pos = *start_pos + UTF8ToUTF16(match.raw_string()).length(); | 82 base::UTF8ToUTF16(utf8_input.substr(0, match.start())).length(); |
| 83 *end_pos = *start_pos + base::UTF8ToUTF16(match.raw_string()).length(); |
| 83 | 84 |
| 84 return true; | 85 return true; |
| 85 } | 86 } |
| 86 | 87 |
| 87 return false; | 88 return false; |
| 88 } | 89 } |
| 89 | 90 |
| 90 } // namespace content | 91 } // namespace content |
| OLD | NEW |