Commit 9fd27b69 authored by Jia's avatar Jia Committed by Commit Bot

[cros search service] Move string_matching to chromeos/components

Our upcoming client has code in src/chromeos/components and cannot
depend on local search service that's in src/chrome. Hence we need
to move local search service to src/chromeos/components.

Some library functions used by local search service are in
src/chrome/common/string_matching. This cl moves these functions
to src/chromeos/components/string_matching. The next cl will
move local search service itself.

Bug: 1102232
Change-Id: I3d17b22b918cd3d1c55d40ef4aa6509da6b28957
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2281798
Commit-Queue: Jia Meng <jiameng@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786145}
parent cdcb8e58
...@@ -91,7 +91,6 @@ source_set("chromeos") { ...@@ -91,7 +91,6 @@ source_set("chromeos") {
"//chrome/browser/web_applications/extensions:extensions", "//chrome/browser/web_applications/extensions:extensions",
"//chrome/common", "//chrome/common",
"//chrome/common/extensions/api", "//chrome/common/extensions/api",
"//chrome/common/string_matching",
"//chrome/installer/util:with_no_strings", "//chrome/installer/util:with_no_strings",
"//chrome/services/file_util/public/cpp", "//chrome/services/file_util/public/cpp",
"//chrome/services/keymaster/public/mojom", "//chrome/services/keymaster/public/mojom",
...@@ -116,6 +115,7 @@ source_set("chromeos") { ...@@ -116,6 +115,7 @@ source_set("chromeos") {
"//chromeos/components/quick_answers/public/cpp:prefs", "//chromeos/components/quick_answers/public/cpp:prefs",
"//chromeos/components/smbfs", "//chromeos/components/smbfs",
"//chromeos/components/smbfs/mojom", "//chromeos/components/smbfs/mojom",
"//chromeos/components/string_matching",
"//chromeos/components/sync_wifi", "//chromeos/components/sync_wifi",
"//chromeos/components/telemetry_extension_ui/mojom", "//chromeos/components/telemetry_extension_ui/mojom",
"//chromeos/components/tether", "//chromeos/components/tether",
......
...@@ -13,14 +13,16 @@ ...@@ -13,14 +13,16 @@
#include "chrome/browser/chromeos/launcher_search_provider/launcher_search_provider_service_factory.h" #include "chrome/browser/chromeos/launcher_search_provider/launcher_search_provider_service_factory.h"
#include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_provider.h" #include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_provider.h"
#include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_result.h" #include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_result.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include "chrome/common/string_matching/tokenized_string_match.h" #include "chromeos/components/string_matching/tokenized_string_match.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/common/extension_set.h" #include "extensions/common/extension_set.h"
#include "extensions/common/permissions/permissions_data.h" #include "extensions/common/permissions/permissions_data.h"
namespace api_launcher_search_provider = namespace api_launcher_search_provider =
extensions::api::launcher_search_provider; extensions::api::launcher_search_provider;
using chromeos::string_matching::TokenizedString;
using chromeos::string_matching::TokenizedStringMatch;
using extensions::ExtensionId; using extensions::ExtensionId;
using extensions::ExtensionSet; using extensions::ExtensionSet;
......
...@@ -15,11 +15,15 @@ ...@@ -15,11 +15,15 @@
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include "third_party/icu/source/i18n/unicode/translit.h" #include "third_party/icu/source/i18n/unicode/translit.h"
namespace local_search_service { namespace local_search_service {
namespace {
using chromeos::string_matching::TokenizedString;
} // namespace
std::vector<Token> ConsolidateToken(const std::vector<Token>& tokens) { std::vector<Token> ConsolidateToken(const std::vector<Token>& tokens) {
std::unordered_map<base::string16, std::vector<WeightedPosition>> dictionary; std::unordered_map<base::string16, std::vector<WeightedPosition>> dictionary;
for (const auto& token : tokens) { for (const auto& token : tokens) {
......
...@@ -12,12 +12,14 @@ ...@@ -12,12 +12,14 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/browser/chromeos/local_search_service/content_extraction_utils.h" #include "chrome/browser/chromeos/local_search_service/content_extraction_utils.h"
#include "chrome/browser/chromeos/local_search_service/inverted_index.h" #include "chrome/browser/chromeos/local_search_service/inverted_index.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
namespace local_search_service { namespace local_search_service {
namespace { namespace {
using chromeos::string_matching::TokenizedString;
std::vector<Token> ExtractDocumentTokens(const Data& data, std::vector<Token> ExtractDocumentTokens(const Data& data,
const std::string& locale) { const std::string& locale) {
std::vector<Token> document_tokens; std::vector<Token> document_tokens;
......
...@@ -10,13 +10,16 @@ ...@@ -10,13 +10,16 @@
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/browser/chromeos/local_search_service/search_utils.h" #include "chrome/browser/chromeos/local_search_service/search_utils.h"
#include "chrome/common/string_matching/fuzzy_tokenized_string_match.h" #include "chromeos/components/string_matching/fuzzy_tokenized_string_match.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
namespace local_search_service { namespace local_search_service {
namespace { namespace {
using chromeos::string_matching::FuzzyTokenizedStringMatch;
using chromeos::string_matching::TokenizedString;
using Positions = std::vector<local_search_service::Position>; using Positions = std::vector<local_search_service::Position>;
using TokenizedStringWithId = using TokenizedStringWithId =
std::pair<std::string, std::unique_ptr<TokenizedString>>; std::pair<std::string, std::unique_ptr<TokenizedString>>;
......
...@@ -15,7 +15,11 @@ ...@@ -15,7 +15,11 @@
#include "chrome/browser/chromeos/local_search_service/index.h" #include "chrome/browser/chromeos/local_search_service/index.h"
#include "chrome/browser/chromeos/local_search_service/shared_structs.h" #include "chrome/browser/chromeos/local_search_service/shared_structs.h"
namespace chromeos {
namespace string_matching {
class TokenizedString; class TokenizedString;
} // namespace string_matching
} // namespace chromeos
namespace local_search_service { namespace local_search_service {
...@@ -48,9 +52,10 @@ class LinearMapSearch : public Index { ...@@ -48,9 +52,10 @@ class LinearMapSearch : public Index {
uint32_t max_results) const; uint32_t max_results) const;
// A map from key to a vector of (tag-id, tokenized tag). // A map from key to a vector of (tag-id, tokenized tag).
std::map< std::map<std::string,
std::string, std::vector<std::pair<
std::vector<std::pair<std::string, std::unique_ptr<TokenizedString>>>> std::string,
std::unique_ptr<chromeos::string_matching::TokenizedString>>>>
data_; data_;
}; };
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/local_search_service/shared_structs.h" #include "chrome/browser/chromeos/local_search_service/shared_structs.h"
#include "chrome/common/string_matching/sequence_matcher.h" #include "chromeos/components/string_matching/sequence_matcher.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include "third_party/icu/source/i18n/unicode/translit.h" #include "third_party/icu/source/i18n/unicode/translit.h"
namespace local_search_service { namespace local_search_service {
...@@ -39,8 +39,9 @@ float ExactPrefixMatchScore(const base::string16& query, ...@@ -39,8 +39,9 @@ float ExactPrefixMatchScore(const base::string16& query,
} }
float BlockMatchScore(const base::string16& query, const base::string16& text) { float BlockMatchScore(const base::string16& query, const base::string16& text) {
return SequenceMatcher(query, text, false /* use_edit_distance */, return chromeos::string_matching::SequenceMatcher(
0.1 /*num_matching_blocks_penalty*/) query, text, false /* use_edit_distance */,
0.1 /*num_matching_blocks_penalty*/)
.Ratio(); .Ratio();
} }
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/browser/chromeos/local_search_service/linear_map_search.h" #include "chrome/browser/chromeos/local_search_service/linear_map_search.h"
#include "chrome/common/string_matching/fuzzy_tokenized_string_match.h" #include "chromeos/components/string_matching/fuzzy_tokenized_string_match.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
namespace local_search_service { namespace local_search_service {
......
...@@ -343,7 +343,6 @@ static_library("ui") { ...@@ -343,7 +343,6 @@ static_library("ui") {
# have the same dependencies. Once browser_ui is untangled from # have the same dependencies. Once browser_ui is untangled from
# browser, then we can clean up these dependencies. # browser, then we can clean up these dependencies.
public_deps = [ public_deps = [
"//chrome/common/string_matching",
"//components/dom_distiller/core", "//components/dom_distiller/core",
"//components/safe_browsing:buildflags", "//components/safe_browsing:buildflags",
"//components/sync", "//components/sync",
...@@ -2469,6 +2468,7 @@ static_library("ui") { ...@@ -2469,6 +2468,7 @@ static_library("ui") {
"//chromeos/components/print_management", "//chromeos/components/print_management",
"//chromeos/components/proximity_auth", "//chromeos/components/proximity_auth",
"//chromeos/components/quick_answers", "//chromeos/components/quick_answers",
"//chromeos/components/string_matching",
"//chromeos/components/tether", "//chromeos/components/tether",
"//chromeos/components/web_applications", "//chromeos/components/web_applications",
"//chromeos/constants", "//chromeos/constants",
......
...@@ -42,9 +42,9 @@ ...@@ -42,9 +42,9 @@
#include "chrome/browser/ui/app_list/search/app_service_app_result.h" #include "chrome/browser/ui/app_list/search/app_service_app_result.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/app_search_result_ranker.h" #include "chrome/browser/ui/app_list/search/search_result_ranker/app_search_result_ranker.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/ranking_item_util.h" #include "chrome/browser/ui/app_list/search/search_result_ranker/ranking_item_util.h"
#include "chrome/common/string_matching/fuzzy_tokenized_string_match.h" #include "chromeos/components/string_matching/fuzzy_tokenized_string_match.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include "chrome/common/string_matching/tokenized_string_match.h" #include "chromeos/components/string_matching/tokenized_string_match.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
#include "components/sync_sessions/session_sync_service.h" #include "components/sync_sessions/session_sync_service.h"
...@@ -65,6 +65,10 @@ constexpr bool kUseEditDistance = false; ...@@ -65,6 +65,10 @@ constexpr bool kUseEditDistance = false;
constexpr double kRelevanceThreshold = 0.32; constexpr double kRelevanceThreshold = 0.32;
constexpr double kPartialMatchPenaltyRate = 0.9; constexpr double kPartialMatchPenaltyRate = 0.9;
using chromeos::string_matching::FuzzyTokenizedStringMatch;
using chromeos::string_matching::TokenizedString;
using chromeos::string_matching::TokenizedStringMatch;
// Adds |app_result| to |results| only in case no duplicate apps were already // Adds |app_result| to |results| only in case no duplicate apps were already
// added. Duplicate means the same app but for different domain, Chrome and // added. Duplicate means the same app but for different domain, Chrome and
// Android. // Android.
......
...@@ -8,8 +8,15 @@ ...@@ -8,8 +8,15 @@
#include "base/containers/adapters.h" #include "base/containers/adapters.h"
#include "chrome/browser/ui/app_list/app_context_menu.h" #include "chrome/browser/ui/app_list/app_context_menu.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include "chrome/common/string_matching/tokenized_string_match.h" #include "chromeos/components/string_matching/tokenized_string_match.h"
namespace {
using chromeos::string_matching::TokenizedString;
using chromeos::string_matching::TokenizedStringMatch;
} // namespace
ChromeSearchResult::ChromeSearchResult() ChromeSearchResult::ChromeSearchResult()
: metadata_(std::make_unique<ash::SearchResultMetadata>()) {} : metadata_(std::make_unique<ash::SearchResultMetadata>()) {}
......
...@@ -15,8 +15,12 @@ ...@@ -15,8 +15,12 @@
#include "chrome/browser/ui/app_list/app_list_model_updater.h" #include "chrome/browser/ui/app_list/app_list_model_updater.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
namespace chromeos {
namespace string_matching {
class TokenizedString; class TokenizedString;
class TokenizedStringMatch; class TokenizedStringMatch;
} // namespace string_matching
} // namespace chromeos
namespace app_list { namespace app_list {
class AppContextMenu; class AppContextMenu;
...@@ -131,8 +135,9 @@ class ChromeSearchResult { ...@@ -131,8 +135,9 @@ class ChromeSearchResult {
// Updates the result's relevance score, and sets its title and title tags, // Updates the result's relevance score, and sets its title and title tags,
// based on a string match result. // based on a string match result.
void UpdateFromMatch(const TokenizedString& title, void UpdateFromMatch(
const TokenizedStringMatch& match); const chromeos::string_matching::TokenizedString& title,
const chromeos::string_matching::TokenizedStringMatch& match);
// Returns the context menu model for this item, or NULL if there is currently // Returns the context menu model for this item, or NULL if there is currently
// no menu for the item (e.g. during install). |callback| takes the ownership // no menu for the item (e.g. during install). |callback| takes the ownership
......
...@@ -3524,12 +3524,6 @@ test("unit_tests") { ...@@ -3524,12 +3524,6 @@ test("unit_tests") {
"../common/pref_names_util_unittest.cc", "../common/pref_names_util_unittest.cc",
"../common/profiler/thread_profiler_unittest.cc", "../common/profiler/thread_profiler_unittest.cc",
"../common/qr_code_generator/qr_code_generator_unittest.cc", "../common/qr_code_generator/qr_code_generator_unittest.cc",
"../common/string_matching/fuzzy_tokenized_string_match_unittest.cc",
"../common/string_matching/sequence_matcher_unittest.cc",
"../common/string_matching/term_break_iterator_unittest.cc",
"../common/string_matching/tokenized_string_char_iterator_unittest.cc",
"../common/string_matching/tokenized_string_match_unittest.cc",
"../common/string_matching/tokenized_string_unittest.cc",
"../renderer/chrome_content_renderer_client_unittest.cc", "../renderer/chrome_content_renderer_client_unittest.cc",
"../renderer/chrome_render_frame_observer_unittest.cc", "../renderer/chrome_render_frame_observer_unittest.cc",
"../renderer/instant_restricted_id_cache_unittest.cc", "../renderer/instant_restricted_id_cache_unittest.cc",
......
...@@ -25,6 +25,7 @@ test("chromeos_components_unittests") { ...@@ -25,6 +25,7 @@ test("chromeos_components_unittests") {
"//chromeos/components/quick_answers:unit_tests", "//chromeos/components/quick_answers:unit_tests",
"//chromeos/components/security_token_pin:unit_tests", "//chromeos/components/security_token_pin:unit_tests",
"//chromeos/components/smbfs:unit_tests", "//chromeos/components/smbfs:unit_tests",
"//chromeos/components/string_matching:unit_tests",
"//chromeos/components/sync_wifi:unit_tests", "//chromeos/components/sync_wifi:unit_tests",
"//chromeos/components/tether:unit_tests", "//chromeos/components/tether:unit_tests",
"//chromeos/components/trial_group:unit_tests", "//chromeos/components/trial_group:unit_tests",
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//build/config/ui.gni") assert(is_chromeos, "Non-ChromeOS builds cannot depend on //chromeos")
import("//chrome/common/features.gni")
source_set("string_matching") { source_set("string_matching") {
sources = [ sources = [
...@@ -24,7 +23,6 @@ source_set("string_matching") { ...@@ -24,7 +23,6 @@ source_set("string_matching") {
] ]
deps = [ deps = [
"//base",
"//base:i18n", "//base:i18n",
"//cc", "//cc",
] ]
...@@ -34,3 +32,21 @@ source_set("string_matching") { ...@@ -34,3 +32,21 @@ source_set("string_matching") {
"//ui/gfx", "//ui/gfx",
] ]
} }
source_set("unit_tests") {
testonly = true
sources = [
"fuzzy_tokenized_string_match_unittest.cc",
"sequence_matcher_unittest.cc",
"term_break_iterator_unittest.cc",
"tokenized_string_char_iterator_unittest.cc",
"tokenized_string_match_unittest.cc",
"tokenized_string_unittest.cc",
]
deps = [
":string_matching",
"//testing/gtest",
]
}
include_rules = [
"+ui/gfx",
]
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/fuzzy_tokenized_string_match.h" #include "chromeos/components/string_matching/fuzzy_tokenized_string_match.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
...@@ -13,8 +13,11 @@ ...@@ -13,8 +13,11 @@
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/common/string_matching/prefix_matcher.h" #include "chromeos/components/string_matching/prefix_matcher.h"
#include "chrome/common/string_matching/sequence_matcher.h" #include "chromeos/components/string_matching/sequence_matcher.h"
namespace chromeos {
namespace string_matching {
namespace { namespace {
constexpr double kMinScore = 0.0; constexpr double kMinScore = 0.0;
...@@ -231,7 +234,7 @@ double FuzzyTokenizedStringMatch::WeightedRatio( ...@@ -231,7 +234,7 @@ double FuzzyTokenizedStringMatch::WeightedRatio(
double FuzzyTokenizedStringMatch::PrefixMatcher(const TokenizedString& query, double FuzzyTokenizedStringMatch::PrefixMatcher(const TokenizedString& query,
const TokenizedString& text) { const TokenizedString& text) {
::PrefixMatcher match(query, text); chromeos::string_matching::PrefixMatcher match(query, text);
match.Match(); match.Match();
return 1.0 - std::pow(0.5, match.relevance()); return 1.0 - std::pow(0.5, match.relevance());
} }
...@@ -303,3 +306,6 @@ bool FuzzyTokenizedStringMatch::IsRelevant(const TokenizedString& query, ...@@ -303,3 +306,6 @@ bool FuzzyTokenizedStringMatch::IsRelevant(const TokenizedString& query,
return relevance_ >= relevance_threshold; return relevance_ >= relevance_threshold;
} }
} // namespace string_matching
} // namespace chromeos
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_COMMON_STRING_MATCHING_FUZZY_TOKENIZED_STRING_MATCH_H_ #ifndef CHROMEOS_COMPONENTS_STRING_MATCHING_FUZZY_TOKENIZED_STRING_MATCH_H_
#define CHROME_COMMON_STRING_MATCHING_FUZZY_TOKENIZED_STRING_MATCH_H_ #define CHROMEOS_COMPONENTS_STRING_MATCHING_FUZZY_TOKENIZED_STRING_MATCH_H_
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include "ui/gfx/range/range.h" #include "ui/gfx/range/range.h"
namespace chromeos {
namespace string_matching {
// FuzzyTokenizedStringMatch takes two tokenized strings: one as the text and // FuzzyTokenizedStringMatch takes two tokenized strings: one as the text and
// the other one as the query. It matches the query against the text, // the other one as the query. It matches the query against the text,
// calculates a relevance score between [0, 1] and marks the matched portions // calculates a relevance score between [0, 1] and marks the matched portions
...@@ -93,4 +96,7 @@ class FuzzyTokenizedStringMatch { ...@@ -93,4 +96,7 @@ class FuzzyTokenizedStringMatch {
DISALLOW_COPY_AND_ASSIGN(FuzzyTokenizedStringMatch); DISALLOW_COPY_AND_ASSIGN(FuzzyTokenizedStringMatch);
}; };
#endif // CHROME_COMMON_STRING_MATCHING_FUZZY_TOKENIZED_STRING_MATCH_H_ } // namespace string_matching
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_STRING_MATCHING_FUZZY_TOKENIZED_STRING_MATCH_H_
...@@ -2,17 +2,22 @@ ...@@ -2,17 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/fuzzy_tokenized_string_match.h" #include "chromeos/components/string_matching/fuzzy_tokenized_string_match.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/common/string_matching/sequence_matcher.h" #include "chromeos/components/string_matching/sequence_matcher.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace string_matching {
namespace { namespace {
constexpr double kPartialMatchPenaltyRate = 0.9; constexpr double kPartialMatchPenaltyRate = 0.9;
} // namespace
class FuzzyTokenizedStringMatchTest : public testing::Test {}; class FuzzyTokenizedStringMatchTest : public testing::Test {};
// TODO(crbug.com/1018613): update the tests once params are consolidated. // TODO(crbug.com/1018613): update the tests once params are consolidated.
...@@ -297,4 +302,5 @@ TEST_F(FuzzyTokenizedStringMatchTest, ExactTextMatchTest) { ...@@ -297,4 +302,5 @@ TEST_F(FuzzyTokenizedStringMatchTest, ExactTextMatchTest) {
EXPECT_EQ(match.hits()[0].end(), 3u); EXPECT_EQ(match.hits()[0].end(), 3u);
} }
} // namespace } // namespace string_matching
} // namespace chromeos
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/prefix_matcher.h" #include "chromeos/components/string_matching/prefix_matcher.h"
#include "base/check.h" #include "base/check.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include "chrome/common/string_matching/tokenized_string_char_iterator.h" #include "chromeos/components/string_matching/tokenized_string_char_iterator.h"
namespace chromeos {
namespace string_matching {
namespace { namespace {
// The factors below are applied when the current char of query matches // The factors below are applied when the current char of query matches
...@@ -144,3 +147,6 @@ void PrefixMatcher::PopState() { ...@@ -144,3 +147,6 @@ void PrefixMatcher::PopState() {
states_.pop_back(); states_.pop_back();
} }
} // namespace string_matching
} // namespace chromeos
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_COMMON_STRING_MATCHING_PREFIX_MATCHER_H_ #ifndef CHROMEOS_COMPONENTS_STRING_MATCHING_PREFIX_MATCHER_H_
#define CHROME_COMMON_STRING_MATCHING_PREFIX_MATCHER_H_ #define CHROMEOS_COMPONENTS_STRING_MATCHING_PREFIX_MATCHER_H_
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include "chrome/common/string_matching/tokenized_string_char_iterator.h" #include "chromeos/components/string_matching/tokenized_string_char_iterator.h"
namespace chromeos {
namespace string_matching {
// PrefixMatcher matches the chars of a given query as prefix of tokens in // PrefixMatcher matches the chars of a given query as prefix of tokens in
// a given text or as prefix of the acronyms of those text tokens. // a given text or as prefix of the acronyms of those text tokens.
...@@ -78,4 +81,7 @@ class PrefixMatcher { ...@@ -78,4 +81,7 @@ class PrefixMatcher {
DISALLOW_COPY_AND_ASSIGN(PrefixMatcher); DISALLOW_COPY_AND_ASSIGN(PrefixMatcher);
}; };
#endif // CHROME_COMMON_STRING_MATCHING_PREFIX_MATCHER_H_ } // namespace string_matching
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_STRING_MATCHING_PREFIX_MATCHER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/sequence_matcher.h" #include "chromeos/components/string_matching/sequence_matcher.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include "base/check_op.h" #include "base/check_op.h"
namespace chromeos {
namespace string_matching {
namespace { namespace {
using Match = SequenceMatcher::Match; using Match = SequenceMatcher::Match;
using Matches = std::vector<Match>; using Matches = std::vector<Match>;
...@@ -204,3 +207,6 @@ double SequenceMatcher::Ratio() { ...@@ -204,3 +207,6 @@ double SequenceMatcher::Ratio() {
} }
return block_matching_ratio_; return block_matching_ratio_;
} }
} // namespace string_matching
} // namespace chromeos
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_COMMON_STRING_MATCHING_SEQUENCE_MATCHER_H_ #ifndef CHROMEOS_COMPONENTS_STRING_MATCHING_SEQUENCE_MATCHER_H_
#define CHROME_COMMON_STRING_MATCHING_SEQUENCE_MATCHER_H_ #define CHROMEOS_COMPONENTS_STRING_MATCHING_SEQUENCE_MATCHER_H_
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
namespace chromeos {
namespace string_matching {
// Performs the calculation of similarity level between 2 strings. This class's // Performs the calculation of similarity level between 2 strings. This class's
// functionality is inspired by python's difflib.SequenceMatcher library. // functionality is inspired by python's difflib.SequenceMatcher library.
// (https://docs.python.org/2/library/difflib.html#difflib.SequenceMatcher) // (https://docs.python.org/2/library/difflib.html#difflib.SequenceMatcher)
...@@ -82,4 +85,7 @@ class SequenceMatcher { ...@@ -82,4 +85,7 @@ class SequenceMatcher {
DISALLOW_COPY_AND_ASSIGN(SequenceMatcher); DISALLOW_COPY_AND_ASSIGN(SequenceMatcher);
}; };
#endif // CHROME_COMMON_STRING_MATCHING_SEQUENCE_MATCHER_H_ } // namespace string_matching
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_STRING_MATCHING_SEQUENCE_MATCHER_H_
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/sequence_matcher.h" #include "chromeos/components/string_matching/sequence_matcher.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace string_matching {
namespace { namespace {
constexpr bool kDefaultUseEditDistance = false; constexpr bool kDefaultUseEditDistance = false;
...@@ -17,6 +20,7 @@ bool MatchEqual(const Match& match1, const Match& match2) { ...@@ -17,6 +20,7 @@ bool MatchEqual(const Match& match1, const Match& match2) {
match1.pos_second_string == match2.pos_second_string && match1.pos_second_string == match2.pos_second_string &&
match1.length == match2.length; match1.length == match2.length;
} }
} // namespace
class SequenceMatcherTest : public testing::Test {}; class SequenceMatcherTest : public testing::Test {};
...@@ -184,4 +188,6 @@ TEST_F(SequenceMatcherTest, TestEditDistanceRatio) { ...@@ -184,4 +188,6 @@ TEST_F(SequenceMatcherTest, TestEditDistanceRatio) {
.Ratio(), .Ratio(),
0.0, 0.01); 0.0, 0.01);
} }
} // namespace
} // namespace string_matching
} // namespace chromeos
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/term_break_iterator.h" #include "chromeos/components/string_matching/term_break_iterator.h"
#include <ostream> #include <ostream>
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "third_party/icu/source/common/unicode/uchar.h" #include "third_party/icu/source/common/unicode/uchar.h"
namespace chromeos {
namespace string_matching {
TermBreakIterator::TermBreakIterator(const base::string16& word) TermBreakIterator::TermBreakIterator(const base::string16& word)
: word_(word), : word_(word),
prev_(npos), prev_(npos),
...@@ -72,3 +75,6 @@ TermBreakIterator::State TermBreakIterator::GetNewState(base::char16 ch) { ...@@ -72,3 +75,6 @@ TermBreakIterator::State TermBreakIterator::GetNewState(base::char16 ch) {
return STATE_CHAR; return STATE_CHAR;
} }
} // namespace string_matching
} // namespace chromeos
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_COMMON_STRING_MATCHING_TERM_BREAK_ITERATOR_H_ #ifndef CHROMEOS_COMPONENTS_STRING_MATCHING_TERM_BREAK_ITERATOR_H_
#define CHROME_COMMON_STRING_MATCHING_TERM_BREAK_ITERATOR_H_ #define CHROMEOS_COMPONENTS_STRING_MATCHING_TERM_BREAK_ITERATOR_H_
#include <stddef.h> #include <stddef.h>
...@@ -18,6 +18,9 @@ class UTF16CharIterator; ...@@ -18,6 +18,9 @@ class UTF16CharIterator;
} }
} // namespace base } // namespace base
namespace chromeos {
namespace string_matching {
// TermBreakIterator breaks terms out of a word. Terms are broken on // TermBreakIterator breaks terms out of a word. Terms are broken on
// camel case boundaries and alpha/number boundaries. Numbers are defined // camel case boundaries and alpha/number boundaries. Numbers are defined
// as [0-9\.,]+. // as [0-9\.,]+.
...@@ -65,4 +68,7 @@ class TermBreakIterator { ...@@ -65,4 +68,7 @@ class TermBreakIterator {
DISALLOW_COPY_AND_ASSIGN(TermBreakIterator); DISALLOW_COPY_AND_ASSIGN(TermBreakIterator);
}; };
#endif // CHROME_COMMON_STRING_MATCHING_TERM_BREAK_ITERATOR_H_ } // namespace string_matching
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_STRING_MATCHING_TERM_BREAK_ITERATOR_H_
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/term_break_iterator.h" #include "chromeos/components/string_matching/term_break_iterator.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using base::UTF8ToUTF16; namespace chromeos {
namespace string_matching {
namespace { using base::UTF8ToUTF16;
TEST(TermBreakIteratorTest, EmptyWord) { TEST(TermBreakIteratorTest, EmptyWord) {
base::string16 empty; base::string16 empty;
...@@ -84,4 +85,5 @@ TEST(TermBreakIteratorTest, CaseAndNoCase) { ...@@ -84,4 +85,5 @@ TEST(TermBreakIteratorTest, CaseAndNoCase) {
EXPECT_FALSE(iter.Advance()); // Test unexpected advance after end. EXPECT_FALSE(iter.Advance()); // Test unexpected advance after end.
} }
} // namespace } // namespace string_matching
} // namespace chromeos
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include <stddef.h> #include <stddef.h>
...@@ -12,7 +12,10 @@ ...@@ -12,7 +12,10 @@
#include "base/notreached.h" #include "base/notreached.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/common/string_matching/term_break_iterator.h" #include "chromeos/components/string_matching/term_break_iterator.h"
namespace chromeos {
namespace string_matching {
using base::i18n::BreakIterator; using base::i18n::BreakIterator;
...@@ -100,3 +103,6 @@ void TokenizedString::TokenizeWords() { ...@@ -100,3 +103,6 @@ void TokenizedString::TokenizeWords() {
mappings_.emplace_back(start, end); mappings_.emplace_back(start, end);
} }
} }
} // namespace string_matching
} // namespace chromeos
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_COMMON_STRING_MATCHING_TOKENIZED_STRING_H_ #ifndef CHROMEOS_COMPONENTS_STRING_MATCHING_TOKENIZED_STRING_H_
#define CHROME_COMMON_STRING_MATCHING_TOKENIZED_STRING_H_ #define CHROMEOS_COMPONENTS_STRING_MATCHING_TOKENIZED_STRING_H_
#include <vector> #include <vector>
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "ui/gfx/range/range.h" #include "ui/gfx/range/range.h"
namespace chromeos {
namespace string_matching {
// TokenizedString takes a string and breaks it down into token words. // TokenizedString takes a string and breaks it down into token words.
class TokenizedString { class TokenizedString {
public: public:
...@@ -46,4 +49,7 @@ class TokenizedString { ...@@ -46,4 +49,7 @@ class TokenizedString {
DISALLOW_COPY_AND_ASSIGN(TokenizedString); DISALLOW_COPY_AND_ASSIGN(TokenizedString);
}; };
#endif // CHROME_COMMON_STRING_MATCHING_TOKENIZED_STRING_H_ } // namespace string_matching
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_STRING_MATCHING_TOKENIZED_STRING_H_
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/tokenized_string_char_iterator.h" #include "chromeos/components/string_matching/tokenized_string_char_iterator.h"
#include "base/check.h" #include "base/check.h"
#include "base/i18n/char_iterator.h" #include "base/i18n/char_iterator.h"
#include "third_party/icu/source/common/unicode/utf16.h" #include "third_party/icu/source/common/unicode/utf16.h"
namespace chromeos {
namespace string_matching {
TokenizedStringCharIterator::State::State() : token_index(0u), char_index(0) {} TokenizedStringCharIterator::State::State() : token_index(0u), char_index(0) {}
TokenizedStringCharIterator::State::State(size_t token_index, int char_index) TokenizedStringCharIterator::State::State(size_t token_index, int char_index)
...@@ -83,3 +86,6 @@ void TokenizedStringCharIterator::CreateTokenCharIterator() { ...@@ -83,3 +86,6 @@ void TokenizedStringCharIterator::CreateTokenCharIterator() {
current_token_iter_.reset( current_token_iter_.reset(
new base::i18n::UTF16CharIterator(&tokens_[current_token_])); new base::i18n::UTF16CharIterator(&tokens_[current_token_]));
} }
} // namespace string_matching
} // namespace chromeos
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_COMMON_STRING_MATCHING_TOKENIZED_STRING_CHAR_ITERATOR_H_ #ifndef CHROMEOS_COMPONENTS_STRING_MATCHING_TOKENIZED_STRING_CHAR_ITERATOR_H_
#define CHROME_COMMON_STRING_MATCHING_TOKENIZED_STRING_CHAR_ITERATOR_H_ #define CHROMEOS_COMPONENTS_STRING_MATCHING_TOKENIZED_STRING_CHAR_ITERATOR_H_
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
namespace base { namespace base {
namespace i18n { namespace i18n {
...@@ -19,6 +19,9 @@ class UTF16CharIterator; ...@@ -19,6 +19,9 @@ class UTF16CharIterator;
} }
} // namespace base } // namespace base
namespace chromeos {
namespace string_matching {
// An UTF16 char iterator for a TokenizedString. // An UTF16 char iterator for a TokenizedString.
class TokenizedStringCharIterator { class TokenizedStringCharIterator {
public: public:
...@@ -73,4 +76,7 @@ class TokenizedStringCharIterator { ...@@ -73,4 +76,7 @@ class TokenizedStringCharIterator {
DISALLOW_COPY_AND_ASSIGN(TokenizedStringCharIterator); DISALLOW_COPY_AND_ASSIGN(TokenizedStringCharIterator);
}; };
#endif // CHROME_COMMON_STRING_MATCHING_TOKENIZED_STRING_CHAR_ITERATOR_H_ } // namespace string_matching
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_STRING_MATCHING_TOKENIZED_STRING_CHAR_ITERATOR_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/tokenized_string_char_iterator.h" #include "chromeos/components/string_matching/tokenized_string_char_iterator.h"
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace string_matching {
namespace { namespace {
// Returns a string represents the current state of |iter|. The state string // Returns a string represents the current state of |iter|. The state string
...@@ -79,6 +82,8 @@ void TestFirstTwoCharInEveryToken(const std::string& text, ...@@ -79,6 +82,8 @@ void TestFirstTwoCharInEveryToken(const std::string& text,
TestBeyondTheEnd(&iter); TestBeyondTheEnd(&iter);
} }
} // namespace
TEST(TokenizedStringCharIteratorTest, NoTerms) { TEST(TokenizedStringCharIteratorTest, NoTerms) {
const char* text; const char* text;
...@@ -142,4 +147,5 @@ TEST(TokenizedStringCharIteratorTest, Basic) { ...@@ -142,4 +147,5 @@ TEST(TokenizedStringCharIteratorTest, Basic) {
TestFirstTwoCharInEveryToken(text, "f0! a1 s9! i10"); TestFirstTwoCharInEveryToken(text, "f0! a1 s9! i10");
} }
} // namespace } // namespace string_matching
} // namespace chromeos
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size < 1 || size % 2 != 0) if (size < 1 || size % 2 != 0)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/tokenized_string_match.h" #include "chromeos/components/string_matching/tokenized_string_match.h"
#include <stddef.h> #include <stddef.h>
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
#include "base/i18n/string_search.h" #include "base/i18n/string_search.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/common/string_matching/prefix_matcher.h" #include "chromeos/components/string_matching/prefix_matcher.h"
namespace chromeos {
namespace string_matching {
namespace { namespace {
// Used for each character if there is no prefix match. // Used for each character if there is no prefix match.
...@@ -79,3 +82,6 @@ bool TokenizedStringMatch::Calculate(const base::string16& query, ...@@ -79,3 +82,6 @@ bool TokenizedStringMatch::Calculate(const base::string16& query,
const TokenizedString tokenized_text(text); const TokenizedString tokenized_text(text);
return Calculate(tokenized_query, tokenized_text); return Calculate(tokenized_query, tokenized_text);
} }
} // namespace string_matching
} // namespace chromeos
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_COMMON_STRING_MATCHING_TOKENIZED_STRING_MATCH_H_ #ifndef CHROMEOS_COMPONENTS_STRING_MATCHING_TOKENIZED_STRING_MATCH_H_
#define CHROME_COMMON_STRING_MATCHING_TOKENIZED_STRING_MATCH_H_ #define CHROMEOS_COMPONENTS_STRING_MATCHING_TOKENIZED_STRING_MATCH_H_
#include <vector> #include <vector>
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "ui/gfx/range/range.h" #include "ui/gfx/range/range.h"
namespace chromeos {
namespace string_matching {
class TokenizedString; class TokenizedString;
// TokenizedStringMatch takes two tokenized strings: one as the text and // TokenizedStringMatch takes two tokenized strings: one as the text and
...@@ -46,4 +49,7 @@ class TokenizedStringMatch { ...@@ -46,4 +49,7 @@ class TokenizedStringMatch {
DISALLOW_COPY_AND_ASSIGN(TokenizedStringMatch); DISALLOW_COPY_AND_ASSIGN(TokenizedStringMatch);
}; };
#endif // CHROME_COMMON_STRING_MATCHING_TOKENIZED_STRING_MATCH_H_ } // namespace string_matching
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_STRING_MATCHING_TOKENIZED_STRING_MATCH_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/tokenized_string_match.h" #include "chromeos/components/string_matching/tokenized_string_match.h"
#include <stddef.h> #include <stddef.h>
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace string_matching {
namespace { namespace {
// Returns a string of |text| marked the hits in |match| using block bracket. // Returns a string of |text| marked the hits in |match| using block bracket.
...@@ -31,6 +34,8 @@ std::string MatchHit(const base::string16& text, ...@@ -31,6 +34,8 @@ std::string MatchHit(const base::string16& text,
return base::UTF16ToUTF8(marked); return base::UTF16ToUTF8(marked);
} }
} // namespace
TEST(TokenizedStringMatchTest, NotMatch) { TEST(TokenizedStringMatchTest, NotMatch) {
struct { struct {
const char* text; const char* text;
...@@ -145,4 +150,5 @@ TEST(TokenizedStringMatchTest, AbsoluteRelevance) { ...@@ -145,4 +150,5 @@ TEST(TokenizedStringMatchTest, AbsoluteRelevance) {
} }
} }
} // namespace } // namespace string_matching
} // namespace chromeos
...@@ -2,13 +2,16 @@ ...@@ -2,13 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/string_matching/tokenized_string.h" #include "chromeos/components/string_matching/tokenized_string.h"
#include <stddef.h> #include <stddef.h>
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace string_matching {
namespace { namespace {
base::string16 GetContent(const TokenizedString& tokenized) { base::string16 GetContent(const TokenizedString& tokenized) {
...@@ -24,6 +27,7 @@ base::string16 GetContent(const TokenizedString& tokenized) { ...@@ -24,6 +27,7 @@ base::string16 GetContent(const TokenizedString& tokenized) {
} }
return str; return str;
} }
} // namespace
TEST(TokenizedStringTest, Empty) { TEST(TokenizedStringTest, Empty) {
base::string16 empty; base::string16 empty;
...@@ -120,4 +124,5 @@ TEST(TokenizedStringTest, TokenizeWords) { ...@@ -120,4 +124,5 @@ TEST(TokenizedStringTest, TokenizeWords) {
} }
} }
} // namespace } // namespace string_matching
} // namespace chromeos
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment