| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/history/snippet.h" | 5 #include "chrome/browser/history/snippet.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 const std::string& query) { | 91 const std::string& query) { |
| 92 // This function assumes that |document| does not contain | 92 // This function assumes that |document| does not contain |
| 93 // any character for which lowercasing changes its length. Further, | 93 // any character for which lowercasing changes its length. Further, |
| 94 // it's assumed that lowercasing only the ASCII-portion works for | 94 // it's assumed that lowercasing only the ASCII-portion works for |
| 95 // |document|. We need to add more test cases and change this function | 95 // |document|. We need to add more test cases and change this function |
| 96 // to be more generic depending on how we deal with 'folding for match' | 96 // to be more generic depending on how we deal with 'folding for match' |
| 97 // in history. | 97 // in history. |
| 98 const std::string document_folded = StringToLowerASCII(std::string(document)); | 98 const std::string document_folded = StringToLowerASCII(std::string(document)); |
| 99 | 99 |
| 100 std::vector<std::string> query_words; | 100 std::vector<std::string> query_words; |
| 101 SplitString(query, ' ', &query_words); | 101 base::SplitString(query, ' ', &query_words); |
| 102 | 102 |
| 103 // Manually construct match_positions of the document. | 103 // Manually construct match_positions of the document. |
| 104 Snippet::MatchPositions match_positions; | 104 Snippet::MatchPositions match_positions; |
| 105 match_positions.clear(); | 105 match_positions.clear(); |
| 106 for (std::vector<std::string>::iterator qw = query_words.begin(); | 106 for (std::vector<std::string>::iterator qw = query_words.begin(); |
| 107 qw != query_words.end(); ++qw) { | 107 qw != query_words.end(); ++qw) { |
| 108 // Insert all instances of this word into match_pairs. | 108 // Insert all instances of this word into match_pairs. |
| 109 size_t ofs = 0; | 109 size_t ofs = 0; |
| 110 while ((ofs = document_folded.find(*qw, ofs)) != std::string::npos) { | 110 while ((ofs = document_folded.find(*qw, ofs)) != std::string::npos) { |
| 111 match_positions.push_back(std::make_pair(ofs, ofs + qw->size())); | 111 match_positions.push_back(std::make_pair(ofs, ofs + qw->size())); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 243 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
| 244 Snippet::MatchPositions matches; | 244 Snippet::MatchPositions matches; |
| 245 Snippet::ExtractMatchPositions(data[i].offsets_string, "0", &matches); | 245 Snippet::ExtractMatchPositions(data[i].offsets_string, "0", &matches); |
| 246 EXPECT_EQ(data[i].expected_match_count, matches.size()); | 246 EXPECT_EQ(data[i].expected_match_count, matches.size()); |
| 247 for (size_t j = 0; j < data[i].expected_match_count; ++j) { | 247 for (size_t j = 0; j < data[i].expected_match_count; ++j) { |
| 248 EXPECT_EQ(data[i].expected_matches[2 * j], matches[j].first); | 248 EXPECT_EQ(data[i].expected_matches[2 * j], matches[j].first); |
| 249 EXPECT_EQ(data[i].expected_matches[2 * j + 1], matches[j].second); | 249 EXPECT_EQ(data[i].expected_matches[2 * j + 1], matches[j].second); |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 } | 252 } |
| OLD | NEW |