| 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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 class PhoneNumberDetectorTest : public testing::Test { | 12 class PhoneNumberDetectorTest : public testing::Test { |
| 13 public: | 13 public: |
| 14 static std::string FindNumber(const std::string& content, | 14 static std::string FindNumber(const std::string& content, |
| 15 const std::string& region) { | 15 const std::string& region) { |
| 16 base::string16 content_16 = UTF8ToUTF16(content); | 16 base::string16 content_16 = base::UTF8ToUTF16(content); |
| 17 base::string16 result_16; | 17 base::string16 result_16; |
| 18 size_t start, end; | 18 size_t start, end; |
| 19 PhoneNumberDetector detector(region); | 19 PhoneNumberDetector detector(region); |
| 20 std::string content_text; | 20 std::string content_text; |
| 21 if (detector.FindContent(content_16.begin(), content_16.end(), | 21 if (detector.FindContent(content_16.begin(), content_16.end(), |
| 22 &start, &end, &content_text)) | 22 &start, &end, &content_text)) |
| 23 result_16 = content_16.substr(start, end - start); | 23 result_16 = content_16.substr(start, end - start); |
| 24 return UTF16ToUTF8(result_16); | 24 return base::UTF16ToUTF8(result_16); |
| 25 } | 25 } |
| 26 | 26 |
| 27 static std::string FindAndFormatNumber(const std::string& content, | 27 static std::string FindAndFormatNumber(const std::string& content, |
| 28 const std::string& region) { | 28 const std::string& region) { |
| 29 base::string16 content_16 = UTF8ToUTF16(content); | 29 base::string16 content_16 = base::UTF8ToUTF16(content); |
| 30 base::string16 result_16; | 30 base::string16 result_16; |
| 31 size_t start, end; | 31 size_t start, end; |
| 32 PhoneNumberDetector detector(region); | 32 PhoneNumberDetector detector(region); |
| 33 std::string content_text; | 33 std::string content_text; |
| 34 detector.FindContent(content_16.begin(), content_16.end(), | 34 detector.FindContent(content_16.begin(), content_16.end(), |
| 35 &start, &end, &content_text); | 35 &start, &end, &content_text); |
| 36 return content_text; | 36 return content_text; |
| 37 } | 37 } |
| 38 }; | 38 }; |
| 39 | 39 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 67 // "+1 (650) 333-6000" using fullwidth UTF-8 characters. | 67 // "+1 (650) 333-6000" using fullwidth UTF-8 characters. |
| 68 EXPECT_EQ("+16503336000", FindAndFormatNumber( | 68 EXPECT_EQ("+16503336000", FindAndFormatNumber( |
| 69 "\xEF\xBC\x8B\xEF\xBC\x91\xE3\x80\x80\xEF\xBC\x88" | 69 "\xEF\xBC\x8B\xEF\xBC\x91\xE3\x80\x80\xEF\xBC\x88" |
| 70 "\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90\xEF\xBC\x89" | 70 "\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90\xEF\xBC\x89" |
| 71 "\xE3\x80\x80\xEF\xBC\x93\xEF\xBC\x93\xEF\xBC\x93" | 71 "\xE3\x80\x80\xEF\xBC\x93\xEF\xBC\x93\xEF\xBC\x93" |
| 72 "\xE3\x83\xBC\xEF\xBC\x96\xEF\xBC\x90\xEF\xBC\x90" | 72 "\xE3\x83\xBC\xEF\xBC\x96\xEF\xBC\x90\xEF\xBC\x90" |
| 73 "\xEF\xBC\x90", "us")); | 73 "\xEF\xBC\x90", "us")); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace content | 76 } // namespace content |
| OLD | NEW |