3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
18 // WARNING: This is an internal header file, included by other C++
19 // standard library headers. You should not attempt to use this header
22 #ifndef _STLP_INTERNAL_COLLATE_H
23 #define _STLP_INTERNAL_COLLATE_H
25 #ifndef _STLP_C_LOCALE_H
26 # include <stl/c_locale.h>
29 #ifndef _STLP_INTERNAL_LOCALE_H
30 # include <stl/_locale.h>
33 #ifndef _STLP_INTERNAL_STRING_H
34 # include <stl/_string.h>
39 template <class _CharT
> class collate
{};
40 template <class _CharT
> class collate_byname
{};
43 class _STLP_CLASS_DECLSPEC collate
<char> : public locale::facet
{
45 typedef char char_type
;
46 typedef string string_type
;
48 explicit collate(size_t __refs
= 0) : locale::facet(__refs
) {}
50 int compare(const char* __low1
, const char* __high1
,
51 const char* __low2
, const char* __high2
) const {
52 return do_compare( __low1
, __high1
, __low2
, __high2
);
55 string_type
transform(const char* __low
, const char* __high
) const {
56 return do_transform(__low
, __high
);
59 long hash(const char* __low
, const char* __high
) const
60 { return do_hash(__low
, __high
); }
62 static _STLP_STATIC_DECLSPEC
locale::id id
;
67 virtual int do_compare(const char*, const char*,
68 const char*, const char*) const;
69 virtual string_type
do_transform(const char*, const char*) const;
70 virtual long do_hash(const char*, const char*) const;
72 collate(const collate
<char>&);
73 collate
<char>& operator =(const collate
<char>&);
76 # ifndef _STLP_NO_WCHAR_T
79 class _STLP_CLASS_DECLSPEC collate
<wchar_t> : public locale::facet
{
81 typedef wchar_t char_type
;
82 typedef wstring string_type
;
84 explicit collate(size_t __refs
= 0) : locale::facet(__refs
) {}
86 int compare(const wchar_t* __low1
, const wchar_t* __high1
,
87 const wchar_t* __low2
, const wchar_t* __high2
) const {
88 return do_compare( __low1
, __high1
, __low2
, __high2
);
91 string_type
transform(const wchar_t* __low
, const wchar_t* __high
) const {
92 return do_transform(__low
, __high
);
95 long hash(const wchar_t* __low
, const wchar_t* __high
) const
96 { return do_hash(__low
, __high
); }
98 static _STLP_STATIC_DECLSPEC
locale::id id
;
103 virtual int do_compare(const wchar_t*, const wchar_t*,
104 const wchar_t*, const wchar_t*) const;
105 virtual string_type
do_transform(const wchar_t*, const wchar_t*) const;
106 virtual long do_hash(const wchar_t* __low
, const wchar_t* __high
) const;
108 collate(const collate
<wchar_t>&);
109 collate
<wchar_t>& operator = (const collate
<wchar_t>&);
112 # endif /* NO_WCHAR_T */
115 class _STLP_CLASS_DECLSPEC collate_byname
<char>: public collate
<char> {
116 friend class _Locale_impl
;
118 explicit collate_byname(const char* __name
, size_t __refs
= 0);
123 virtual int do_compare(const char*, const char*,
124 const char*, const char*) const;
125 virtual string_type
do_transform(const char*, const char*) const;
128 collate_byname(_Locale_collate
*__coll
)
129 : _M_collate(__coll
) {}
130 _Locale_collate
* _M_collate
;
131 collate_byname(const collate_byname
<char>&);
132 collate_byname
<char>& operator =(const collate_byname
<char>&);
135 # ifndef _STLP_NO_WCHAR_T
138 class _STLP_CLASS_DECLSPEC collate_byname
<wchar_t>: public collate
<wchar_t> {
139 friend class _Locale_impl
;
141 explicit collate_byname(const char * __name
, size_t __refs
= 0);
146 virtual int do_compare(const wchar_t*, const wchar_t*,
147 const wchar_t*, const wchar_t*) const;
148 virtual string_type
do_transform(const wchar_t*, const wchar_t*) const;
151 collate_byname(_Locale_collate
*__coll
)
152 : _M_collate(__coll
) {}
153 _Locale_collate
* _M_collate
;
154 collate_byname(const collate_byname
<wchar_t>&);
155 collate_byname
<wchar_t>& operator =(const collate_byname
<wchar_t>&);
158 # endif /* NO_WCHAR_T */
160 template <class _CharT
, class _Traits
, class _Alloc
>
162 __locale_do_operator_call (const locale
& __loc
,
163 const basic_string
<_CharT
, _Traits
, _Alloc
>& __x
,
164 const basic_string
<_CharT
, _Traits
, _Alloc
>& __y
) {
165 collate
<_CharT
> const& __coll
= use_facet
<collate
<_CharT
> >(__loc
);
166 return __coll
.compare(__x
.data(), __x
.data() + __x
.size(),
167 __y
.data(), __y
.data() + __y
.size()) < 0;
172 #endif /* _STLP_INTERNAL_COLLATE_H */