• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1999
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
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.
16  *
17  */
18 // WARNING: This is an internal header file, included by other C++
19 // standard library headers.  You should not attempt to use this header
20 // file directly.
21 
22 #ifndef _STLP_INTERNAL_COLLATE_H
23 #define _STLP_INTERNAL_COLLATE_H
24 
25 #ifndef _STLP_C_LOCALE_H
26 # include <stl/c_locale.h>
27 #endif
28 
29 #ifndef _STLP_INTERNAL_LOCALE_H
30 # include <stl/_locale.h>
31 #endif
32 
33 #ifndef _STLP_INTERNAL_STRING_H
34 # include <stl/_string.h>
35 #endif
36 
37 _STLP_BEGIN_NAMESPACE
38 
39 template <class _CharT> class collate {};
40 template <class _CharT> class collate_byname {};
41 
42 _STLP_TEMPLATE_NULL
43 class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet {
44 public:
45   typedef char   char_type;
46   typedef string string_type;
47 
facet(__refs)48   explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
49 
compare(const char * __low1,const char * __high1,const char * __low2,const char * __high2)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);
53   }
54 
transform(const char * __low,const char * __high)55   string_type transform(const char* __low, const char* __high) const {
56     return do_transform(__low, __high);
57   }
58 
hash(const char * __low,const char * __high)59   long hash(const char* __low, const char* __high) const
60     { return do_hash(__low, __high); }
61 
62   static _STLP_STATIC_DECLSPEC locale::id id;
63 
64 protected:
65   ~collate();
66 
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;
71 private:
72   collate(const collate<char>&);
73   collate<char>& operator =(const collate<char>&);
74 };
75 
76 # ifndef _STLP_NO_WCHAR_T
77 
78 _STLP_TEMPLATE_NULL
79 class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet {
80 public:
81   typedef wchar_t char_type;
82   typedef wstring string_type;
83 
facet(__refs)84   explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
85 
compare(const wchar_t * __low1,const wchar_t * __high1,const wchar_t * __low2,const wchar_t * __high2)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);
89   }
90 
transform(const wchar_t * __low,const wchar_t * __high)91   string_type transform(const wchar_t* __low, const wchar_t* __high) const {
92     return do_transform(__low, __high);
93   }
94 
hash(const wchar_t * __low,const wchar_t * __high)95   long hash(const wchar_t* __low, const wchar_t* __high) const
96     { return do_hash(__low, __high); }
97 
98   static _STLP_STATIC_DECLSPEC locale::id id;
99 
100 protected:
101   ~collate();
102 
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;
107 private:
108   collate(const collate<wchar_t>&);
109   collate<wchar_t>& operator = (const collate<wchar_t>&);
110 };
111 
112 # endif /* NO_WCHAR_T */
113 
114 _STLP_TEMPLATE_NULL
115 class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char> {
116   friend class _Locale_impl;
117 public:
118   explicit collate_byname(const char* __name, size_t __refs = 0);
119 
120 protected:
121   ~collate_byname();
122 
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;
126 
127 private:
collate_byname(_Locale_collate * __coll)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>&);
133 };
134 
135 # ifndef _STLP_NO_WCHAR_T
136 
137 _STLP_TEMPLATE_NULL
138 class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t> {
139   friend class _Locale_impl;
140 public:
141   explicit collate_byname(const char * __name, size_t __refs = 0);
142 
143 protected:
144   ~collate_byname();
145 
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;
149 
150 private:
collate_byname(_Locale_collate * __coll)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>&);
156 };
157 
158 # endif /* NO_WCHAR_T */
159 
160 template <class _CharT, class _Traits, class _Alloc>
161 bool
__locale_do_operator_call(const locale & __loc,const basic_string<_CharT,_Traits,_Alloc> & __x,const basic_string<_CharT,_Traits,_Alloc> & __y)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;
168 }
169 
170 _STLP_END_NAMESPACE
171 
172 #endif /* _STLP_INTERNAL_COLLATE_H */
173 
174 // Local Variables:
175 // mode:C++
176 // End:
177