| 6 | #define BASE_I18N_STRING_SEARCH_H_ |
| 7 |
| 8 | #include <stddef.h> |
| 9 |
| 10 | #include "base/i18n/base_i18n_export.h" |
| 11 | #include "base/strings/string16.h" |
| 12 |
| 13 | struct UStringSearch; |
| 14 |
| 15 | namespace base { |
| 16 | namespace i18n { |
| 17 |
| 18 | // Returns true if |in_this| contains |find_this|. If |match_index| or |
| 19 | // |match_length| are non-NULL, they are assigned the start position and total |
| 20 | // length of the match. |
| 21 | // |
| 22 | // Only differences between base letters are taken into consideration. Case and |
| 23 | // accent differences are ignored. Please refer to 'primary level' in |
| 24 | // http://userguide.icu-project.org/collation/concepts for additional details. |
| 25 | BASE_I18N_EXPORT |
| 26 | bool StringSearchIgnoringCaseAndAccents(const string16& find_this, |
| 27 | const string16& in_this, |
| 28 | size_t* match_index, |
| 29 | size_t* match_length); |
| 30 |
| 31 | // Returns true if |in_this| contains |find_this|. If |match_index| or |
| 32 | // |match_length| are non-NULL, they are assigned the start position and total |
| 33 | // length of the match. |
| 34 | // |
| 35 | // When |case_sensitive| is false, only differences between base letters are |
| 36 | // taken into consideration. Case and accent differences are ignored. |
| 37 | // Please refer to 'primary level' in |
| 38 | // http://userguide.icu-project.org/collation/concepts for additional details. |
| 39 | // When |forward_search| is true, finds the first instance of |find_this|, |
| 40 | // otherwise finds the last instance |
| 41 | BASE_I18N_EXPORT |
| 42 | bool StringSearch(const string16& find_this, |
| 43 | const string16& in_this, |
| 44 | size_t* match_index, |
| 45 | size_t* match_length, |
| 46 | bool case_sensitive, |
| 47 | bool forward_search); |
| 48 |
| 49 | // This class is for speeding up multiple StringSearch() |
| 50 | // with the same |find_this| argument. |find_this| is passed as the constructor |
| 51 | // argument, and precomputation for searching is done only at that time. |
| 52 | class BASE_I18N_EXPORT FixedPatternStringSearch { |
| 53 | public: |
| 54 | explicit FixedPatternStringSearch(const string16& find_this, |
| 55 | bool case_sensitive); |
| 56 | ~FixedPatternStringSearch(); |
| 57 |
| 58 | // Returns true if |in_this| contains |find_this|. If |match_index| or |
| 59 | // |match_length| are non-NULL, they are assigned the start position and total |
| 60 | // length of the match. |
| 61 | bool Search(const string16& in_this, |
| 62 | size_t* match_index, |
| 63 | size_t* match_length, |
| 64 | bool forward_search); |
| 65 |
| 66 | private: |
| 67 | string16 find_this_; |
| 68 | UStringSearch* search_; |
| 69 | }; |
| 70 |
| 71 | // This class is for speeding up multiple StringSearchIgnoringCaseAndAccents() |
| 72 | // with the same |find_this| argument. |find_this| is passed as the constructor |
| 73 | // argument, and precomputation for searching is done only at that time. |
| 74 | class BASE_I18N_EXPORT FixedPatternStringSearchIgnoringCaseAndAccents { |
| 75 | public: |
| 76 | explicit FixedPatternStringSearchIgnoringCaseAndAccents( |
| 77 | const string16& find_this); |
| 78 |
| 79 | // Returns true if |in_this| contains |find_this|. If |match_index| or |
| 80 | // |match_length| are non-NULL, they are assigned the start position and total |
| 81 | // length of the match. |
| 82 | bool Search(const string16& in_this, |
| 83 | size_t* match_index, |
| 84 | size_t* match_length); |
| 85 |
| 86 | private: |
| 87 | FixedPatternStringSearch base_search_; |
| 88 | }; |
| 89 |
| 90 | } // namespace i18n |
| 91 | } // namespace base |
| 92 |
| 93 | #endif // BASE_I18N_STRING_SEARCH_H_ |
| 94 |