OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 13 matching lines...) Expand all Loading... |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #ifndef WTF_Collator_h | 29 #ifndef WTF_Collator_h |
30 #define WTF_Collator_h | 30 #define WTF_Collator_h |
31 | 31 |
32 #include "wtf/Allocator.h" | 32 #include "wtf/Allocator.h" |
33 #include "wtf/Noncopyable.h" | 33 #include "wtf/Noncopyable.h" |
34 #include "wtf/PassOwnPtr.h" | |
35 #include "wtf/WTFExport.h" | 34 #include "wtf/WTFExport.h" |
36 #include "wtf/text/Unicode.h" | 35 #include "wtf/text/Unicode.h" |
| 36 #include <memory> |
37 | 37 |
38 struct UCollator; | 38 struct UCollator; |
39 | 39 |
40 namespace WTF { | 40 namespace WTF { |
41 | 41 |
42 class WTF_EXPORT Collator { | 42 class WTF_EXPORT Collator { |
43 WTF_MAKE_NONCOPYABLE(Collator); | 43 WTF_MAKE_NONCOPYABLE(Collator); |
44 USING_FAST_MALLOC(Collator); | 44 USING_FAST_MALLOC(Collator); |
45 public: | 45 public: |
46 enum Result { Equal = 0, Greater = 1, Less = -1 }; | 46 enum Result { Equal = 0, Greater = 1, Less = -1 }; |
47 | 47 |
48 // From ICU's uloc.h (ULOC_FULLNAME_CAPACITY) | 48 // From ICU's uloc.h (ULOC_FULLNAME_CAPACITY) |
49 static const size_t ulocFullnameCapacity = 157; | 49 static const size_t ulocFullnameCapacity = 157; |
50 | 50 |
51 Collator(const char* locale); // Parsing is lenient; e.g. language identifie
rs (such as "en-US") are accepted, too. | 51 Collator(const char* locale); // Parsing is lenient; e.g. language identifie
rs (such as "en-US") are accepted, too. |
52 ~Collator(); | 52 ~Collator(); |
53 void setOrderLowerFirst(bool); | 53 void setOrderLowerFirst(bool); |
54 | 54 |
55 static PassOwnPtr<Collator> userDefault(); | 55 static std::unique_ptr<Collator> userDefault(); |
56 | 56 |
57 Result collate(const ::UChar*, size_t, const ::UChar*, size_t) const; | 57 Result collate(const ::UChar*, size_t, const ::UChar*, size_t) const; |
58 | 58 |
59 private: | 59 private: |
60 void createCollator() const; | 60 void createCollator() const; |
61 void releaseCollator(); | 61 void releaseCollator(); |
62 void setEquivalentLocale(const char*, char*); | 62 void setEquivalentLocale(const char*, char*); |
63 mutable UCollator* m_collator; | 63 mutable UCollator* m_collator; |
64 | 64 |
65 char* m_locale; | 65 char* m_locale; |
66 char m_equivalentLocale[ulocFullnameCapacity]; | 66 char m_equivalentLocale[ulocFullnameCapacity]; |
67 bool m_lowerFirst; | 67 bool m_lowerFirst; |
68 }; | 68 }; |
69 | 69 |
70 } // namespace WTF | 70 } // namespace WTF |
71 | 71 |
72 using WTF::Collator; | 72 using WTF::Collator; |
73 | 73 |
74 #endif | 74 #endif |
OLD | NEW |