2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
20 // WARNING: This is an internal header file, included by other C++
21 // standard library headers. You should not attempt to use this header
24 #ifndef _STLP_INTERNAL_COLLATE_H
25 #define _STLP_INTERNAL_COLLATE_H
27 #ifndef _STLP_C_LOCALE_H
28 # include <stl/c_locale.h>
31 #ifndef _STLP_INTERNAL_LOCALE_H
32 # include <stl/_locale.h>
35 #ifndef _STLP_INTERNAL_STRING_H
36 # include <stl/_string.h>
41 template <class _CharT> class collate {};
42 template <class _CharT> class collate_byname {};
45 class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet
47 friend class _Locale_impl;
50 typedef char char_type;
51 typedef string string_type;
53 explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
55 int compare(const char* __low1, const char* __high1,
56 const char* __low2, const char* __high2) const {
57 return do_compare( __low1, __high1, __low2, __high2);
60 string_type transform(const char* __low, const char* __high) const {
61 return do_transform(__low, __high);
64 long hash(const char* __low, const char* __high) const
65 { return do_hash(__low, __high); }
67 #if defined(__SYMBIAN32__WSD__)
68 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
69 #elif defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
70 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
73 // NOTE: Symbian doesn't support exporting static data.
74 // Users of this class should use GetFacetLocaleId() to access the data member id
75 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
79 _STLP_DECLSPEC ~collate();
81 _STLP_DECLSPEC virtual int do_compare(const char*, const char*,
82 const char*, const char*) const;
83 _STLP_DECLSPEC virtual string_type do_transform(const char*, const char*) const;
84 _STLP_DECLSPEC virtual long do_hash(const char*, const char*) const;
86 collate(const collate<char>&);
87 collate<char>& operator =(const collate<char>&);
90 # ifndef _STLP_NO_WCHAR_T
93 class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet
95 friend class _Locale_impl;
98 typedef wchar_t char_type;
99 typedef wstring string_type;
101 explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
103 int compare(const wchar_t* __low1, const wchar_t* __high1,
104 const wchar_t* __low2, const wchar_t* __high2) const {
105 return do_compare( __low1, __high1, __low2, __high2);
108 string_type transform(const wchar_t* __low, const wchar_t* __high) const {
109 return do_transform(__low, __high);
112 long hash(const wchar_t* __low, const wchar_t* __high) const
113 { return do_hash(__low, __high); }
115 #if defined(__SYMBIAN32__WSD__)
116 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
117 #elif defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
118 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
119 static locale::id id;
121 // NOTE: Symbian doesn't support exporting static data.
122 // Users of this class should use GetFacetLocaleId() to access the data member id
123 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
127 _STLP_DECLSPEC ~collate();
129 _STLP_DECLSPEC virtual int do_compare(const wchar_t*, const wchar_t*,
130 const wchar_t*, const wchar_t*) const;
131 _STLP_DECLSPEC virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
132 _STLP_DECLSPEC virtual long do_hash(const wchar_t* __low, const wchar_t* __high) const;
134 collate(const collate<wchar_t>&);
135 collate<wchar_t>& operator = (const collate<wchar_t>&);
138 # endif /* NO_WCHAR_T */
141 class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char>
144 _STLP_DECLSPEC explicit collate_byname(const char* __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
147 _STLP_DECLSPEC ~collate_byname();
149 _STLP_DECLSPEC virtual int do_compare(const char*, const char*,
150 const char*, const char*) const;
151 _STLP_DECLSPEC virtual string_type do_transform(const char*, const char*) const;
154 _Locale_collate* _M_collate;
155 collate_byname(const collate_byname<char>&);
156 collate_byname<char>& operator =(const collate_byname<char>&);
157 friend _Locale_name_hint* _Locale_extract_hint(collate_byname<char>*);
160 # ifndef _STLP_NO_WCHAR_T
163 class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t>
166 _STLP_DECLSPEC explicit collate_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
169 _STLP_DECLSPEC ~collate_byname();
171 _STLP_DECLSPEC virtual int do_compare(const wchar_t*, const wchar_t*,
172 const wchar_t*, const wchar_t*) const;
173 _STLP_DECLSPEC virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
176 _Locale_collate* _M_collate;
177 collate_byname(const collate_byname<wchar_t>&);
178 collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);
181 # endif /* NO_WCHAR_T */
183 template <class _CharT, class _Traits, class _Alloc>
185 __locale_do_operator_call (const locale& __loc,
186 const basic_string<_CharT, _Traits, _Alloc>& __x,
187 const basic_string<_CharT, _Traits, _Alloc>& __y) {
188 collate<_CharT> const& __coll = use_facet<collate<_CharT> >(__loc);
189 return __coll.compare(__x.data(), __x.data() + __x.size(),
190 __y.data(), __y.data() + __y.size()) < 0;
195 #endif /* _STLP_INTERNAL_COLLATE_H */