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 "chrome/browser/bookmarks/bookmark_index.h" | 5 #include "components/bookmarks/core/browser/bookmark_index.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <list> | 10 #include <list> |
11 | 11 |
12 #include "base/i18n/case_conversion.h" | 12 #include "base/i18n/case_conversion.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/utf_offset_string_conversions.h" | 15 #include "base/strings/utf_offset_string_conversions.h" |
16 #include "chrome/browser/bookmarks/bookmark_utils.h" | |
17 #include "components/bookmarks/core/browser/bookmark_client.h" | 16 #include "components/bookmarks/core/browser/bookmark_client.h" |
18 #include "components/bookmarks/core/browser/bookmark_match.h" | 17 #include "components/bookmarks/core/browser/bookmark_match.h" |
19 #include "components/bookmarks/core/browser/bookmark_node.h" | 18 #include "components/bookmarks/core/browser/bookmark_node.h" |
| 19 #include "components/bookmarks/core/browser/bookmark_utils.h" |
20 #include "components/query_parser/query_parser.h" | 20 #include "components/query_parser/query_parser.h" |
21 #include "components/query_parser/snippet.h" | 21 #include "components/query_parser/snippet.h" |
22 #include "third_party/icu/source/common/unicode/normalizer2.h" | 22 #include "third_party/icu/source/common/unicode/normalizer2.h" |
23 | 23 |
24 typedef BookmarkClient::NodeTypedCountPair NodeTypedCountPair; | 24 typedef BookmarkClient::NodeTypedCountPair NodeTypedCountPair; |
25 typedef BookmarkClient::NodeTypedCountPairs NodeTypedCountPairs; | 25 typedef BookmarkClient::NodeTypedCountPairs NodeTypedCountPairs; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Returns a normalized version of the UTF16 string |text|. If it fails to | 29 // Returns a normalized version of the UTF16 string |text|. If it fails to |
30 // normalize the string, returns |text| itself as a best-effort. | 30 // normalize the string, returns |text| itself as a best-effort. |
31 base::string16 Normalize(const base::string16& text) { | 31 base::string16 Normalize(const base::string16& text) { |
32 UErrorCode status = U_ZERO_ERROR; | 32 UErrorCode status = U_ZERO_ERROR; |
33 const icu::Normalizer2* normalizer2 = | 33 const icu::Normalizer2* normalizer2 = |
34 icu::Normalizer2::getInstance(NULL, "nfkc", UNORM2_COMPOSE, status); | 34 icu::Normalizer2::getInstance(NULL, "nfkc", UNORM2_COMPOSE, status); |
35 icu::UnicodeString unicode_text(text.data(), text.length()); | 35 icu::UnicodeString unicode_text( |
| 36 text.data(), static_cast<int32_t>(text.length())); |
36 icu::UnicodeString unicode_normalized_text; | 37 icu::UnicodeString unicode_normalized_text; |
37 normalizer2->normalize(unicode_text, unicode_normalized_text, status); | 38 normalizer2->normalize(unicode_text, unicode_normalized_text, status); |
38 if (U_FAILURE(status)) | 39 if (U_FAILURE(status)) |
39 return text; | 40 return text; |
40 return base::string16(unicode_normalized_text.getBuffer(), | 41 return base::string16(unicode_normalized_text.getBuffer(), |
41 unicode_normalized_text.length()); | 42 unicode_normalized_text.length()); |
42 } | 43 } |
43 | 44 |
44 // Sort functor for NodeTypedCountPairs. We sort in decreasing order of typed | 45 // Sort functor for NodeTypedCountPairs. We sort in decreasing order of typed |
45 // count so that the best matches will always be added to the results. | 46 // count so that the best matches will always be added to the results. |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 Index::iterator i = index_.find(term); | 358 Index::iterator i = index_.find(term); |
358 if (i == index_.end()) { | 359 if (i == index_.end()) { |
359 // We can get here if the node has the same term more than once. For | 360 // We can get here if the node has the same term more than once. For |
360 // example, a bookmark with the title 'foo foo' would end up here. | 361 // example, a bookmark with the title 'foo foo' would end up here. |
361 return; | 362 return; |
362 } | 363 } |
363 i->second.erase(node); | 364 i->second.erase(node); |
364 if (i->second.empty()) | 365 if (i->second.empty()) |
365 index_.erase(i); | 366 index_.erase(i); |
366 } | 367 } |
OLD | NEW |