OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ | 5 #ifndef UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ |
6 #define UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ | 6 #define UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <functional> | 10 #include <functional> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "ui/ui_api.h" | 16 #include "ui/base/ui_export.h" |
17 #include "unicode/coll.h" | 17 #include "unicode/coll.h" |
18 | 18 |
19 namespace l10n_util { | 19 namespace l10n_util { |
20 | 20 |
21 // Compares the two strings using the specified collator. | 21 // Compares the two strings using the specified collator. |
22 UI_API UCollationResult CompareString16WithCollator( | 22 UI_EXPORT UCollationResult CompareString16WithCollator( |
23 const icu::Collator* collator, | 23 const icu::Collator* collator, |
24 const string16& lhs, | 24 const string16& lhs, |
25 const string16& rhs); | 25 const string16& rhs); |
26 | 26 |
27 // Used by SortStringsUsingMethod. Invokes a method on the objects passed to | 27 // Used by SortStringsUsingMethod. Invokes a method on the objects passed to |
28 // operator (), comparing the string results using a collator. | 28 // operator (), comparing the string results using a collator. |
29 template <class T, class Method> | 29 template <class T, class Method> |
30 class StringMethodComparatorWithCollator | 30 class StringMethodComparatorWithCollator |
31 : public std::binary_function<const string16&, | 31 : public std::binary_function<const string16&, |
32 const string16&, | 32 const string16&, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 return StringComparator<string16>(collator_)(lhs_string_key, | 106 return StringComparator<string16>(collator_)(lhs_string_key, |
107 rhs_string_key); | 107 rhs_string_key); |
108 } | 108 } |
109 | 109 |
110 private: | 110 private: |
111 icu::Collator* collator_; | 111 icu::Collator* collator_; |
112 }; | 112 }; |
113 | 113 |
114 // Specialization of operator() method for string16 version. | 114 // Specialization of operator() method for string16 version. |
115 template <> UI_API | 115 template <> UI_EXPORT |
116 bool StringComparator<string16>::operator()(const string16& lhs, | 116 bool StringComparator<string16>::operator()(const string16& lhs, |
117 const string16& rhs); | 117 const string16& rhs); |
118 | 118 |
119 // In place sorting of |elements| of a vector according to the string key of | 119 // In place sorting of |elements| of a vector according to the string key of |
120 // each element in the vector by using collation rules for |locale|. | 120 // each element in the vector by using collation rules for |locale|. |
121 // |begin_index| points to the start position of elements in the vector which | 121 // |begin_index| points to the start position of elements in the vector which |
122 // want to be sorted. |end_index| points to the end position of elements in the | 122 // want to be sorted. |end_index| points to the end position of elements in the |
123 // vector which want to be sorted | 123 // vector which want to be sorted |
124 template <class Element> | 124 template <class Element> |
125 void SortVectorWithStringKey(const std::string& locale, | 125 void SortVectorWithStringKey(const std::string& locale, |
(...skipping 22 matching lines...) Expand all Loading... |
148 void SortVectorWithStringKey(const std::string& locale, | 148 void SortVectorWithStringKey(const std::string& locale, |
149 std::vector<Element>* elements, | 149 std::vector<Element>* elements, |
150 bool needs_stable_sort) { | 150 bool needs_stable_sort) { |
151 SortVectorWithStringKey<Element>(locale, elements, 0, elements->size(), | 151 SortVectorWithStringKey<Element>(locale, elements, 0, elements->size(), |
152 needs_stable_sort); | 152 needs_stable_sort); |
153 } | 153 } |
154 | 154 |
155 } // namespace l10n_util | 155 } // namespace l10n_util |
156 | 156 |
157 #endif // UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ | 157 #endif // UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ |
OLD | NEW |