| 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 "unicode/coll.h" | 16 #include "unicode/coll.h" |
| 17 | 17 |
| 18 namespace l10n_util { | 18 namespace l10n_util { |
| 19 | 19 |
| 20 // Compares the two strings using the specified collator. | 20 // Compares the two strings using the specified collator. |
| 21 UCollationResult CompareString16WithCollator(const icu::Collator* collator, | 21 UI_BASE_API UCollationResult CompareString16WithCollator( |
| 22 const string16& lhs, | 22 const icu::Collator* collator, |
| 23 const string16& rhs); | 23 const string16& lhs, |
| 24 const string16& rhs); |
| 24 | 25 |
| 25 // Used by SortStringsUsingMethod. Invokes a method on the objects passed to | 26 // Used by SortStringsUsingMethod. Invokes a method on the objects passed to |
| 26 // operator (), comparing the string results using a collator. | 27 // operator (), comparing the string results using a collator. |
| 27 template <class T, class Method> | 28 template <class T, class Method> |
| 28 class StringMethodComparatorWithCollator | 29 class StringMethodComparatorWithCollator |
| 29 : public std::binary_function<const string16&, | 30 : public std::binary_function<const string16&, |
| 30 const string16&, | 31 const string16&, |
| 31 bool> { | 32 bool> { |
| 32 public: | 33 public: |
| 33 StringMethodComparatorWithCollator(icu::Collator* collator, Method method) | 34 StringMethodComparatorWithCollator(icu::Collator* collator, Method method) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 104 |
| 104 return StringComparator<string16>(collator_)(lhs_string_key, | 105 return StringComparator<string16>(collator_)(lhs_string_key, |
| 105 rhs_string_key); | 106 rhs_string_key); |
| 106 } | 107 } |
| 107 | 108 |
| 108 private: | 109 private: |
| 109 icu::Collator* collator_; | 110 icu::Collator* collator_; |
| 110 }; | 111 }; |
| 111 | 112 |
| 112 // Specialization of operator() method for string16 version. | 113 // Specialization of operator() method for string16 version. |
| 113 template <> | 114 template <> UI_BASE_API |
| 114 bool StringComparator<string16>::operator()(const string16& lhs, | 115 bool StringComparator<string16>::operator()(const string16& lhs, |
| 115 const string16& rhs); | 116 const string16& rhs); |
| 116 | 117 |
| 117 // In place sorting of |elements| of a vector according to the string key of | 118 // In place sorting of |elements| of a vector according to the string key of |
| 118 // each element in the vector by using collation rules for |locale|. | 119 // each element in the vector by using collation rules for |locale|. |
| 119 // |begin_index| points to the start position of elements in the vector which | 120 // |begin_index| points to the start position of elements in the vector which |
| 120 // want to be sorted. |end_index| points to the end position of elements in the | 121 // want to be sorted. |end_index| points to the end position of elements in the |
| 121 // vector which want to be sorted | 122 // vector which want to be sorted |
| 122 template <class Element> | 123 template <class Element> |
| 123 void SortVectorWithStringKey(const std::string& locale, | 124 void SortVectorWithStringKey(const std::string& locale, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 146 void SortVectorWithStringKey(const std::string& locale, | 147 void SortVectorWithStringKey(const std::string& locale, |
| 147 std::vector<Element>* elements, | 148 std::vector<Element>* elements, |
| 148 bool needs_stable_sort) { | 149 bool needs_stable_sort) { |
| 149 SortVectorWithStringKey<Element>(locale, elements, 0, elements->size(), | 150 SortVectorWithStringKey<Element>(locale, elements, 0, elements->size(), |
| 150 needs_stable_sort); | 151 needs_stable_sort); |
| 151 } | 152 } |
| 152 | 153 |
| 153 } // namespace l10n_util | 154 } // namespace l10n_util |
| 154 | 155 |
| 155 #endif // UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ | 156 #endif // UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ |
| OLD | NEW |