1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_I18N_STRING_SEARCH_H_
6 #define BASE_I18N_STRING_SEARCH_H_
12 #include "base/i18n/base_i18n_export.h"
13 #include "base/memory/raw_ptr.h"
20 // Returns true if |in_this| contains |find_this|. If |match_index| or
21 // |match_length| are non-NULL, they are assigned the start position and total
22 // length of the match.
24 // Only differences between base letters are taken into consideration. Case and
25 // accent differences are ignored. Please refer to 'primary level' in
26 // http://userguide.icu-project.org/collation/concepts for additional details.
28 bool StringSearchIgnoringCaseAndAccents(const std::u16string& find_this,
29 const std::u16string& in_this,
31 size_t* match_length);
33 // Returns true if |in_this| contains |find_this|. If |match_index| or
34 // |match_length| are non-NULL, they are assigned the start position and total
35 // length of the match.
37 // When |case_sensitive| is false, only differences between base letters are
38 // taken into consideration. Case and accent differences are ignored.
39 // Please refer to 'primary level' in
40 // http://userguide.icu-project.org/collation/concepts for additional details.
41 // When |forward_search| is true, finds the first instance of |find_this|,
42 // otherwise finds the last instance
44 bool StringSearch(const std::u16string& find_this,
45 const std::u16string& in_this,
51 // This class is for speeding up multiple StringSearch()
52 // with the same |find_this| argument. |find_this| is passed as the constructor
53 // argument, and precomputation for searching is done only at that time.
54 class BASE_I18N_EXPORT FixedPatternStringSearch {
56 explicit FixedPatternStringSearch(const std::u16string& find_this,
58 ~FixedPatternStringSearch();
60 // Returns true if |in_this| contains |find_this|. If |match_index| or
61 // |match_length| are non-NULL, they are assigned the start position and total
62 // length of the match.
63 bool Search(const std::u16string& in_this,
69 std::u16string find_this_;
70 raw_ptr<UStringSearch, DanglingUntriaged> search_;
73 // This class is for speeding up multiple StringSearchIgnoringCaseAndAccents()
74 // with the same |find_this| argument. |find_this| is passed as the constructor
75 // argument, and precomputation for searching is done only at that time.
76 class BASE_I18N_EXPORT FixedPatternStringSearchIgnoringCaseAndAccents {
78 explicit FixedPatternStringSearchIgnoringCaseAndAccents(
79 const std::u16string& find_this);
81 // Returns true if |in_this| contains |find_this|. If |match_index| or
82 // |match_length| are non-NULL, they are assigned the start position and total
83 // length of the match.
84 bool Search(const std::u16string& in_this,
86 size_t* match_length);
89 FixedPatternStringSearch base_search_;
92 // This class is for performing all matches of `find_this` in `in_this`.
93 // `find_this` and `in_this` are passed as arguments in constructor.
94 class BASE_I18N_EXPORT RepeatingStringSearch {
96 RepeatingStringSearch(const std::u16string& find_this,
97 const std::u16string& in_this,
99 ~RepeatingStringSearch();
101 // Returns true if the next match exists. `match_index` and `match_length` are
102 // assigned the start position and total length of the match.
103 bool NextMatchResult(int& match_index, int& match_length);
106 std::u16string find_this_;
107 std::u16string in_this_;
108 raw_ptr<UStringSearch> search_;
114 #endif // BASE_I18N_STRING_SEARCH_H_