williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@2
|
3 |
*
|
williamr@2
|
4 |
* Copyright (c) 1999
|
williamr@2
|
5 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
6 |
*
|
williamr@2
|
7 |
* Copyright (c) 1999
|
williamr@2
|
8 |
* Boris Fomitchev
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
11 |
* or implied. Any use is at your own risk.
|
williamr@2
|
12 |
*
|
williamr@2
|
13 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
14 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
15 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
16 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
17 |
* modified is included with the above copyright notice.
|
williamr@2
|
18 |
*
|
williamr@2
|
19 |
*/
|
williamr@2
|
20 |
// WARNING: This is an internal header file, included by other C++
|
williamr@2
|
21 |
// standard library headers. You should not attempt to use this header
|
williamr@2
|
22 |
// file directly.
|
williamr@2
|
23 |
|
williamr@2
|
24 |
#ifndef _STLP_INTERNAL_COLLATE_H
|
williamr@2
|
25 |
#define _STLP_INTERNAL_COLLATE_H
|
williamr@2
|
26 |
|
williamr@2
|
27 |
#ifndef _STLP_C_LOCALE_H
|
williamr@2
|
28 |
# include <stl/c_locale.h>
|
williamr@2
|
29 |
#endif
|
williamr@2
|
30 |
|
williamr@2
|
31 |
#ifndef _STLP_INTERNAL_LOCALE_H
|
williamr@2
|
32 |
# include <stl/_locale.h>
|
williamr@2
|
33 |
#endif
|
williamr@2
|
34 |
|
williamr@2
|
35 |
#ifndef _STLP_STRING_H
|
williamr@2
|
36 |
# include <stl/_string.h>
|
williamr@2
|
37 |
#endif
|
williamr@2
|
38 |
|
williamr@2
|
39 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
40 |
|
williamr@2
|
41 |
|
williamr@2
|
42 |
template <class _CharT> class collate {};
|
williamr@2
|
43 |
template <class _CharT> class collate_byname {};
|
williamr@2
|
44 |
|
williamr@2
|
45 |
_STLP_TEMPLATE_NULL
|
williamr@2
|
46 |
#ifdef __SYMBIAN32__
|
williamr@2
|
47 |
class collate<char> : public locale::facet
|
williamr@2
|
48 |
#else
|
williamr@2
|
49 |
class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet
|
williamr@2
|
50 |
#endif
|
williamr@2
|
51 |
{
|
williamr@2
|
52 |
friend class _Locale;
|
williamr@2
|
53 |
public:
|
williamr@2
|
54 |
typedef char char_type;
|
williamr@2
|
55 |
typedef string string_type;
|
williamr@2
|
56 |
|
williamr@2
|
57 |
explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
|
williamr@2
|
58 |
|
williamr@2
|
59 |
int compare(const char* __low1, const char* __high1,
|
williamr@2
|
60 |
const char* __low2, const char* __high2) const {
|
williamr@2
|
61 |
return do_compare( __low1, __high1, __low2, __high2);
|
williamr@2
|
62 |
}
|
williamr@2
|
63 |
|
williamr@2
|
64 |
string_type transform(const char* __low, const char* __high) const {
|
williamr@2
|
65 |
return do_transform(__low, __high);
|
williamr@2
|
66 |
}
|
williamr@2
|
67 |
|
williamr@2
|
68 |
long hash(const char* __low, const char* __high) const
|
williamr@2
|
69 |
{ return do_hash(__low, __high); }
|
williamr@2
|
70 |
|
williamr@2
|
71 |
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
|
williamr@2
|
72 |
_STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId();
|
williamr@2
|
73 |
#else
|
williamr@2
|
74 |
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
|
williamr@2
|
75 |
#endif
|
williamr@2
|
76 |
|
williamr@2
|
77 |
protected:
|
williamr@2
|
78 |
_STLP_DECLSPEC ~collate();
|
williamr@2
|
79 |
|
williamr@2
|
80 |
_STLP_DECLSPEC virtual int do_compare(const char*, const char*,
|
williamr@2
|
81 |
const char*, const char*) const;
|
williamr@2
|
82 |
_STLP_DECLSPEC virtual string_type do_transform(const char*, const char*) const;
|
williamr@2
|
83 |
_STLP_DECLSPEC virtual long do_hash(const char*, const char*) const;
|
williamr@2
|
84 |
private:
|
williamr@2
|
85 |
collate(const collate<char>&);
|
williamr@2
|
86 |
collate<char>& operator =(const collate<char>&);
|
williamr@2
|
87 |
};
|
williamr@2
|
88 |
|
williamr@2
|
89 |
# ifndef _STLP_NO_WCHAR_T
|
williamr@2
|
90 |
|
williamr@2
|
91 |
_STLP_TEMPLATE_NULL
|
williamr@2
|
92 |
#ifdef __SYMBIAN32__
|
williamr@2
|
93 |
class collate<wchar_t> : public locale::facet
|
williamr@2
|
94 |
#else
|
williamr@2
|
95 |
class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet
|
williamr@2
|
96 |
#endif
|
williamr@2
|
97 |
{
|
williamr@2
|
98 |
friend class _Locale;
|
williamr@2
|
99 |
public:
|
williamr@2
|
100 |
typedef wchar_t char_type;
|
williamr@2
|
101 |
typedef wstring string_type;
|
williamr@2
|
102 |
|
williamr@2
|
103 |
explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
|
williamr@2
|
104 |
|
williamr@2
|
105 |
int compare(const wchar_t* __low1, const wchar_t* __high1,
|
williamr@2
|
106 |
const wchar_t* __low2, const wchar_t* __high2) const {
|
williamr@2
|
107 |
return do_compare( __low1, __high1, __low2, __high2);
|
williamr@2
|
108 |
}
|
williamr@2
|
109 |
|
williamr@2
|
110 |
string_type transform(const wchar_t* __low, const wchar_t* __high) const {
|
williamr@2
|
111 |
return do_transform(__low, __high);
|
williamr@2
|
112 |
}
|
williamr@2
|
113 |
|
williamr@2
|
114 |
long hash(const wchar_t* __low, const wchar_t* __high) const
|
williamr@2
|
115 |
{ return do_hash(__low, __high); }
|
williamr@2
|
116 |
|
williamr@2
|
117 |
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
|
williamr@2
|
118 |
_STLP_STATIC_MEMBER_DECLSPEC static locale::id& GetFacetLocaleId();
|
williamr@2
|
119 |
#else
|
williamr@2
|
120 |
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
|
williamr@2
|
121 |
#endif
|
williamr@2
|
122 |
|
williamr@2
|
123 |
protected:
|
williamr@2
|
124 |
_STLP_DECLSPEC ~collate();
|
williamr@2
|
125 |
|
williamr@2
|
126 |
_STLP_DECLSPEC virtual int do_compare(const wchar_t*, const wchar_t*,
|
williamr@2
|
127 |
const wchar_t*, const wchar_t*) const;
|
williamr@2
|
128 |
_STLP_DECLSPEC virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
|
williamr@2
|
129 |
_STLP_DECLSPEC virtual long do_hash(const wchar_t* __low, const wchar_t* __high) const;
|
williamr@2
|
130 |
private:
|
williamr@2
|
131 |
collate(const collate<wchar_t>&);
|
williamr@2
|
132 |
collate<wchar_t>& operator = (const collate<wchar_t>&);
|
williamr@2
|
133 |
};
|
williamr@2
|
134 |
|
williamr@2
|
135 |
# endif /* NO_WCHAR_T */
|
williamr@2
|
136 |
|
williamr@2
|
137 |
_STLP_TEMPLATE_NULL
|
williamr@2
|
138 |
class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char>
|
williamr@2
|
139 |
{
|
williamr@2
|
140 |
public:
|
williamr@2
|
141 |
explicit _STLP_DECLSPEC collate_byname(const char* __name, size_t __refs = 0);
|
williamr@2
|
142 |
|
williamr@2
|
143 |
protected:
|
williamr@2
|
144 |
_STLP_DECLSPEC ~collate_byname();
|
williamr@2
|
145 |
|
williamr@2
|
146 |
_STLP_DECLSPEC virtual int do_compare(const char*, const char*,
|
williamr@2
|
147 |
const char*, const char*) const;
|
williamr@2
|
148 |
_STLP_DECLSPEC virtual string_type do_transform(const char*, const char*) const;
|
williamr@2
|
149 |
|
williamr@2
|
150 |
private:
|
williamr@2
|
151 |
_Locale_collate* _M_collate;
|
williamr@2
|
152 |
collate_byname(const collate_byname<char>&);
|
williamr@2
|
153 |
collate_byname<char>& operator =(const collate_byname<char>&);
|
williamr@2
|
154 |
};
|
williamr@2
|
155 |
|
williamr@2
|
156 |
# ifndef _STLP_NO_WCHAR_T
|
williamr@2
|
157 |
|
williamr@2
|
158 |
_STLP_TEMPLATE_NULL
|
williamr@2
|
159 |
class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t>
|
williamr@2
|
160 |
{
|
williamr@2
|
161 |
public:
|
williamr@2
|
162 |
explicit _STLP_DECLSPEC collate_byname(const char * __name, size_t __refs = 0);
|
williamr@2
|
163 |
|
williamr@2
|
164 |
protected:
|
williamr@2
|
165 |
_STLP_DECLSPEC ~collate_byname();
|
williamr@2
|
166 |
|
williamr@2
|
167 |
_STLP_DECLSPEC virtual int do_compare(const wchar_t*, const wchar_t*,
|
williamr@2
|
168 |
const wchar_t*, const wchar_t*) const;
|
williamr@2
|
169 |
_STLP_DECLSPEC virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
|
williamr@2
|
170 |
|
williamr@2
|
171 |
private:
|
williamr@2
|
172 |
_Locale_collate* _M_collate;
|
williamr@2
|
173 |
collate_byname(const collate_byname<wchar_t>&);
|
williamr@2
|
174 |
collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);
|
williamr@2
|
175 |
};
|
williamr@2
|
176 |
|
williamr@2
|
177 |
# endif /* NO_WCHAR_T */
|
williamr@2
|
178 |
|
williamr@2
|
179 |
|
williamr@2
|
180 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
181 |
bool
|
williamr@2
|
182 |
__locale_do_operator_call (const locale* __that,
|
williamr@2
|
183 |
const basic_string<_CharT, _Traits, _Alloc >& __x,
|
williamr@2
|
184 |
const basic_string<_CharT, _Traits, _Alloc >& __y)
|
williamr@2
|
185 |
{
|
williamr@2
|
186 |
#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
|
williamr@2
|
187 |
collate<_CharT>* __f = (collate<_CharT>*)__that->_M_get_facet(collate<_CharT>::GetFacetLocaleId());
|
williamr@2
|
188 |
#else
|
williamr@2
|
189 |
collate<_CharT>* __f = (collate<_CharT>*)__that->_M_get_facet(collate<_CharT>::id);
|
williamr@2
|
190 |
#endif
|
williamr@2
|
191 |
if (!__f)
|
williamr@2
|
192 |
__that->_M_throw_runtime_error();
|
williamr@2
|
193 |
return __f->compare(__x.data(), __x.data() + __x.size(),
|
williamr@2
|
194 |
__y.data(), __y.data() + __y.size()) < 0;
|
williamr@2
|
195 |
|
williamr@2
|
196 |
}
|
williamr@2
|
197 |
|
williamr@2
|
198 |
_STLP_END_NAMESPACE
|
williamr@2
|
199 |
|
williamr@2
|
200 |
#endif /* _STLP_INTERNAL_COLLATE_H */
|
williamr@2
|
201 |
|
williamr@2
|
202 |
// Local Variables:
|
williamr@2
|
203 |
// mode:C++
|
williamr@2
|
204 |
// End:
|