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
3 // found in the LICENSE file.
5 #include "content/renderer/android/address_detector.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "content/common/android/address_parser.h"
12 #include "content/public/renderer/android_content_detection_prefixes.h"
13 #include "net/base/escape.h"
17 // Maximum text length to be searched for address detection.
18 static const size_t kMaxAddressLength
= 250;
20 } // anonymous namespace
24 AddressDetector::AddressDetector() {
27 AddressDetector::~AddressDetector() {
30 GURL
AddressDetector::GetIntentURL(const std::string
& content_text
) {
31 return GURL(kAddressPrefix
+
32 net::EscapeQueryParamValue(content_text
, true));
35 size_t AddressDetector::GetMaximumContentLength() {
36 return kMaxAddressLength
;
39 std::string
AddressDetector::GetContentText(const base::string16
& text
) {
40 // Get the address and replace unicode bullets with commas.
41 base::string16 address_16
= base::CollapseWhitespace(text
, false);
42 std::replace(address_16
.begin(), address_16
.end(),
43 static_cast<base::char16
>(0x2022), static_cast<base::char16
>(','));
44 return base::UTF16ToUTF8(address_16
);
47 bool AddressDetector::FindContent(
48 const base::string16::const_iterator
& begin
,
49 const base::string16::const_iterator
& end
,
52 std::string
* content_text
) {
53 if (address_parser::FindAddress(begin
, end
, start_pos
, end_pos
)) {
55 GetContentText(base::string16(begin
+ *start_pos
, begin
+ *end_pos
)));
61 } // namespace content