diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-23 15:35:25 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-23 15:35:25 +0000 |
commit | e5366896e9ccb3dd17c590d115bd999e987a33af (patch) | |
tree | 52f4fc2f07b73aaca1199adb1384b123130c22ed /chrome/browser/bookmarks | |
parent | b133cc2db84fc83d5c4aa53020237788fa344c75 (diff) | |
download | chromium_src-e5366896e9ccb3dd17c590d115bd999e987a33af.zip chromium_src-e5366896e9ccb3dd17c590d115bd999e987a33af.tar.gz chromium_src-e5366896e9ccb3dd17c590d115bd999e987a33af.tar.bz2 |
Replace wstring with string16 in history. The only time wstring is used now in history is for bookmark-related stuff (the bookmarks system is still wstring-based).
The substantial change here is in RTL to make a string16 variant of the functions and in changing the WordIterator to use string16 (this cleaned up some weird utf-32 code).
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/2808017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50597 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_index.cc | 22 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_index_unittest.cc | 23 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_utils.cc | 25 |
3 files changed, 41 insertions, 29 deletions
diff --git a/chrome/browser/bookmarks/bookmark_index.cc b/chrome/browser/bookmarks/bookmark_index.cc index 18c3134..161058e 100644 --- a/chrome/browser/bookmarks/bookmark_index.cc +++ b/chrome/browser/bookmarks/bookmark_index.cc @@ -62,7 +62,7 @@ void BookmarkIndex::GetBookmarksWithTitlesMatching( // matches and so this shouldn't be performance critical. QueryParser parser; ScopedVector<QueryNode> query_nodes; - parser.ParseQuery(query, &query_nodes.get()); + parser.ParseQuery(WideToUTF16(query), &query_nodes.get()); // The highest typed counts should be at the beginning of the results vector // so that the best matches will always be included in the results. The loop @@ -115,7 +115,7 @@ void BookmarkIndex::AddMatchToResults( // of QueryParser may filter it out. For example, the query // ["thi"] will match the bookmark titled [Thinking], but since // ["thi"] is quoted we don't want to do a prefix match. - if (parser->DoesQueryMatch(node->GetTitle(), query_nodes, + if (parser->DoesQueryMatch(WideToUTF16(node->GetTitle()), query_nodes, &(title_match.match_positions))) { title_match.node = node; results->push_back(title_match); @@ -129,7 +129,7 @@ bool BookmarkIndex::GetBookmarksWithTitleMatchingTerm(const std::wstring& term, if (i == index_.end()) return false; - if (!QueryParser::IsWordLongEnoughForPrefixSearch(term)) { + if (!QueryParser::IsWordLongEnoughForPrefixSearch(WideToUTF16(term))) { // Term is too short for prefix match, compare using exact match. if (i->first != term) return false; // No bookmarks with this term. @@ -206,13 +206,23 @@ void BookmarkIndex::CombineMatches(const Index::const_iterator& index_i, std::vector<std::wstring> BookmarkIndex::ExtractQueryWords( const std::wstring& query) { - std::vector<std::wstring> terms; + std::vector<string16> terms; if (query.empty()) - return terms; + return std::vector<std::wstring>(); QueryParser parser; // TODO: use ICU normalization. - parser.ExtractQueryWords(l10n_util::ToLower(query), &terms); + parser.ExtractQueryWords(l10n_util::ToLower(WideToUTF16(query)), &terms); + + // TODO(brettw) just remove this and return |terms| when this is converted + // to string16. +#if defined(WCHAR_T_IS_UTF32) + std::vector<std::wstring> wterms; + for (size_t i = 0; i < terms.size(); i++) + wterms.push_back(UTF16ToWide(terms[i])); + return wterms; +#else return terms; +#endif } void BookmarkIndex::RegisterNode(const std::wstring& term, diff --git a/chrome/browser/bookmarks/bookmark_index_unittest.cc b/chrome/browser/bookmarks/bookmark_index_unittest.cc index cfc1972..6225bc7 100644 --- a/chrome/browser/bookmarks/bookmark_index_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_index_unittest.cc @@ -232,41 +232,42 @@ TEST_F(BookmarkIndexTest, GetResultsSortedByTypedCount) { struct TestData { const GURL url; - const std::wstring title; + const char* title; const int typed_count; } data[] = { - { GURL("http://www.google.com/"), L"Google", 100 }, - { GURL("http://maps.google.com/"), L"Google Maps", 40 }, - { GURL("http://docs.google.com/"), L"Google Docs", 50 }, - { GURL("http://reader.google.com/"), L"Google Reader", 80 }, + { GURL("http://www.google.com/"), "Google", 100 }, + { GURL("http://maps.google.com/"), "Google Maps", 40 }, + { GURL("http://docs.google.com/"), "Google Docs", 50 }, + { GURL("http://reader.google.com/"), "Google Reader", 80 }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { history::URLRow info(data[i].url); - info.set_title(data[i].title); + info.set_title(UTF8ToUTF16(data[i].title)); info.set_typed_count(data[i].typed_count); // Populate the InMemoryDatabase.... url_db->AddURL(info); // Populate the BookmarkIndex. - model->AddURL(model->other_node(), i, data[i].title, data[i].url); + model->AddURL(model->other_node(), i, UTF8ToWide(data[i].title), + data[i].url); } // Check that the InMemoryDatabase stored the URLs properly. history::URLRow result1; url_db->GetRowForURL(data[0].url, &result1); - EXPECT_EQ(data[0].title, result1.title()); + EXPECT_EQ(data[0].title, UTF16ToUTF8(result1.title())); history::URLRow result2; url_db->GetRowForURL(data[1].url, &result2); - EXPECT_EQ(data[1].title, result2.title()); + EXPECT_EQ(data[1].title, UTF16ToUTF8(result2.title())); history::URLRow result3; url_db->GetRowForURL(data[2].url, &result3); - EXPECT_EQ(data[2].title, result3.title()); + EXPECT_EQ(data[2].title, UTF16ToUTF8(result3.title())); history::URLRow result4; url_db->GetRowForURL(data[3].url, &result4); - EXPECT_EQ(data[3].title, result4.title()); + EXPECT_EQ(data[3].title, UTF16ToUTF8(result4.title())); // Populate match nodes. std::vector<bookmark_utils::TitleMatch> matches; diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc index 2f4bc18..63cf429 100644 --- a/chrome/browser/bookmarks/bookmark_utils.cc +++ b/chrome/browser/bookmarks/bookmark_utils.cc @@ -204,8 +204,8 @@ bool MoreRecentlyModified(const BookmarkNode* n1, const BookmarkNode* n2) { // Returns true if |text| contains each string in |words|. This is used when // searching for bookmarks. -bool DoesBookmarkTextContainWords(const std::wstring& text, - const std::vector<std::wstring>& words) { +bool DoesBookmarkTextContainWords(const string16& text, + const std::vector<string16>& words) { for (size_t i = 0; i < words.size(); ++i) { if (text.find(words[i]) == std::wstring::npos) return false; @@ -216,16 +216,17 @@ bool DoesBookmarkTextContainWords(const std::wstring& text, // Returns true if |node|s title or url contains the strings in |words|. // |languages| argument is user's accept-language setting to decode IDN. bool DoesBookmarkContainWords(const BookmarkNode* node, - const std::vector<std::wstring>& words, + const std::vector<string16>& words, const std::wstring& languages) { return DoesBookmarkTextContainWords( - l10n_util::ToLower(node->GetTitle()), words) || + l10n_util::ToLower(WideToUTF16(node->GetTitle())), words) || DoesBookmarkTextContainWords( - l10n_util::ToLower(UTF8ToWide(node->GetURL().spec())), words) || - DoesBookmarkTextContainWords(l10n_util::ToLower(net::FormatUrl( - node->GetURL(), languages, net::kFormatUrlOmitNothing, - UnescapeRule::NORMAL, NULL, NULL, NULL)), words); + l10n_util::ToLower(UTF8ToUTF16(node->GetURL().spec())), words) || + DoesBookmarkTextContainWords(l10n_util::ToLower(WideToUTF16( + net::FormatUrl( + node->GetURL(), languages, net::kFormatUrlOmitNothing, + UnescapeRule::NORMAL, NULL, NULL, NULL))), words); } } // namespace @@ -530,9 +531,9 @@ void GetBookmarksContainingText(BookmarkModel* model, size_t max_count, const std::wstring& languages, std::vector<const BookmarkNode*>* nodes) { - std::vector<std::wstring> words; + std::vector<string16> words; QueryParser parser; - parser.ExtractQueryWords(l10n_util::ToLower(text), &words); + parser.ExtractQueryWords(l10n_util::ToLower(WideToUTF16(text)), &words); if (words.empty()) return; @@ -550,9 +551,9 @@ void GetBookmarksContainingText(BookmarkModel* model, bool DoesBookmarkContainText(const BookmarkNode* node, const std::wstring& text, const std::wstring& languages) { - std::vector<std::wstring> words; + std::vector<string16> words; QueryParser parser; - parser.ExtractQueryWords(l10n_util::ToLower(text), &words); + parser.ExtractQueryWords(l10n_util::ToLower(WideToUTF16(text)), &words); if (words.empty()) return false; |