|
|
|
1 |
|
// xlocinfo internal header for Microsoft |
2 |
|
#pragma once |
3 |
|
#ifndef _XLOCINFO_ |
4 |
|
#define _XLOCINFO_ |
5 |
|
#ifndef RC_INVOKED |
6 |
|
#include <xlocinfo.h> |
7 |
|
#include <cstdlib> |
8 |
|
#include <xstddef> |
9 |
|
|
10 |
|
#ifdef _MSC_VER |
11 |
|
#pragma pack(push,_CRT_PACKING) |
12 |
|
#pragma warning(push,3) |
13 |
|
#pragma warning(disable:4412) |
14 |
|
#endif /* _MSC_VER */ |
15 |
|
|
16 |
|
_STD_BEGIN |
17 |
|
|
18 |
|
// CLASS _Timevec |
19 |
|
class _CRTIMP2_PURE _Timevec |
20 |
|
{ // smart pointer to information used by _Strftime |
21 |
|
public: |
22 |
|
__CLR_OR_THIS_CALL _Timevec(void *_Ptr = 0) |
23 |
|
: _Timeptr(_Ptr) |
24 |
|
{ // construct from ptr |
25 |
|
} |
26 |
|
|
27 |
|
__CLR_OR_THIS_CALL _Timevec(const _Timevec& _Right) |
28 |
|
{ // construct from _Right |
29 |
|
*this = _Right; |
30 |
|
} |
31 |
|
|
32 |
|
__CLR_OR_THIS_CALL ~_Timevec() |
33 |
|
{ // destroy the object |
34 |
|
free(_Timeptr); |
35 |
|
} |
36 |
|
|
37 |
|
_Timevec& __CLR_OR_THIS_CALL operator=(const _Timevec& _Right) |
38 |
|
{ // transfer ownership of _Timeptr from _Right |
39 |
|
_Timeptr = _Right._Timeptr; |
40 |
|
((_Timevec *)&_Right)->_Timeptr = 0; |
41 |
|
return (*this); |
42 |
|
} |
43 |
|
|
44 |
|
void *__CLR_OR_THIS_CALL _Getptr() const |
45 |
|
{ // return pointer to time information |
46 |
|
return (_Timeptr); |
47 |
|
} |
48 |
|
|
49 |
|
private: |
50 |
|
void *_Timeptr; // pointer to time information |
51 |
|
}; |
52 |
|
|
53 |
|
// CLASS _Locinfo |
54 |
|
|
55 |
|
// warning 4412 is benign here |
56 |
|
#pragma warning(push) |
57 |
|
#pragma warning(disable:4412) |
58 |
|
class _CRTIMP2_PURE _Locinfo |
59 |
|
{ // summary of all stuff peculiar to a locale used by standard facets |
60 |
|
public: |
61 |
|
typedef ::_Collvec _Collvec; |
62 |
|
typedef ::_Ctypevec _Ctypevec; |
63 |
|
typedef ::_Cvtvec _Cvtvec; |
64 |
|
typedef std::_Timevec _Timevec; |
65 |
|
|
66 |
|
static _MRTIMP2_NPURE void __cdecl _Locinfo_ctor(_Locinfo *, const char *); |
67 |
|
static _MRTIMP2_NPURE void __cdecl _Locinfo_ctor(_Locinfo *, const string&); |
68 |
|
static _MRTIMP2_NPURE void __cdecl _Locinfo_ctor(_Locinfo *, int, const char *); |
69 |
|
static _MRTIMP2_NPURE void __cdecl _Locinfo_dtor(_Locinfo *); |
70 |
|
static _MRTIMP2_NPURE _Locinfo& __cdecl _Locinfo_Addcats(_Locinfo *, int, const char *); |
71 |
|
|
72 |
|
__CLR_OR_THIS_CALL _Locinfo(const char *_Pch = "C") |
73 |
|
#ifndef _M_CEE |
74 |
|
: _Lock(_LOCK_LOCALE) |
75 |
|
#endif |
76 |
|
{ |
77 |
|
if (_Pch == 0) |
78 |
|
_THROW_NCEE(runtime_error, "bad locale name"); |
79 |
|
_Locinfo_ctor(this, _Pch); |
80 |
|
} |
81 |
|
|
82 |
|
__CLR_OR_THIS_CALL _Locinfo(int _I, const char *_Pch) |
83 |
|
#ifndef _M_CEE |
84 |
|
: _Lock(_LOCK_LOCALE) |
85 |
|
#endif |
86 |
|
{ |
87 |
|
if (_Pch == 0) |
88 |
|
_THROW_NCEE(runtime_error, "bad locale name"); |
89 |
|
_Locinfo_ctor(this, _I, _Pch); |
90 |
|
} |
91 |
|
|
92 |
|
__CLR_OR_THIS_CALL _Locinfo(const string& locstr) |
93 |
|
#ifndef _M_CEE |
94 |
|
: _Lock(_LOCK_LOCALE) |
95 |
|
#endif |
96 |
|
{ |
97 |
|
_Locinfo_ctor(this, locstr); |
98 |
|
} |
99 |
|
|
100 |
|
__CLR_OR_THIS_CALL ~_Locinfo() |
101 |
|
{ |
102 |
|
_Locinfo_dtor(this); |
103 |
|
} |
104 |
|
|
105 |
|
_Locinfo& __CLR_OR_THIS_CALL _Addcats(int _I, const char *_Pch) |
106 |
|
{ |
107 |
|
if (_Pch == 0) |
108 |
|
_THROW(runtime_error, "bad locale name"); |
109 |
|
return _Locinfo_Addcats(this, _I, _Pch); |
110 |
|
} |
111 |
|
|
112 |
|
string __CLR_OR_THIS_CALL _Getname() const |
113 |
|
{ // return the new locale name |
114 |
|
return (_Newlocname); |
115 |
|
} |
116 |
|
|
117 |
|
_Collvec __CLR_OR_THIS_CALL _Getcoll() const |
118 |
|
{ // return collation stuff |
119 |
|
return (::_Getcoll()); |
120 |
|
} |
121 |
|
|
122 |
|
_Ctypevec __CLR_OR_THIS_CALL _Getctype() const |
123 |
|
{ // return ctype stuff |
124 |
|
return (::_Getctype()); |
125 |
|
} |
126 |
|
|
127 |
|
_Cvtvec __CLR_OR_THIS_CALL _Getcvt() const |
128 |
|
{ // return codecvt stuff |
129 |
|
return (::_Getcvt()); |
130 |
|
} |
131 |
|
|
132 |
|
const lconv *__CLR_OR_THIS_CALL _Getlconv() const |
133 |
|
{ // return localeconv stuff |
134 |
|
return (localeconv()); |
145 |
|
if (_Ptr != 0) |
146 |
|
{ // capture names and free allocated C string |
147 |
|
((_Locinfo *)this)->_Days = _Ptr; |
148 |
|
free((void *)_Ptr); |
149 |
|
} |
150 |
|
return (_Days.size() != 0 ? _Days.c_str() |
151 |
|
: ":Sun:Sunday:Mon:Monday:Tue:Tuesday:Wed:Wednesday" |
152 |
|
":Thu:Thursday:Fri:Friday:Sat:Saturday"); |
153 |
|
} |
154 |
|
|
155 |
|
const char *__CLR_OR_THIS_CALL _Getmonths() const |
156 |
|
{ // return names for months |
157 |
|
const char *_Ptr = ::_Getmonths(); |
158 |
|
if (_Ptr != 0) |
159 |
|
{ // capture names and free allocated C string |
160 |
|
((_Locinfo *)this)->_Months = _Ptr; |
161 |
|
free((void *)_Ptr); |
162 |
|
} |
163 |
|
return (_Months.size() != 0 ? _Months.c_str() |
164 |
|
: ":Jan:January:Feb:February:Mar:March" |
165 |
|
":Apr:April:May:May:Jun:June" |
166 |
|
":Jul:July:Aug:August:Sep:September" |
167 |
|
":Oct:October:Nov:November:Dec:December"); |
168 |
|
} |
169 |
|
|
170 |
|
const char *__CLR_OR_THIS_CALL _Getfalse() const |
171 |
|
{ // return false name (no C source) |
172 |
|
return ("false"); |
173 |
|
} |
174 |
|
|
175 |
|
const char *__CLR_OR_THIS_CALL _Gettrue() const |
176 |
|
{ // return true name (no C source) |
177 |
|
return ("true"); |
178 |
|
} |
179 |
|
|
180 |
|
int __CLR_OR_THIS_CALL _Getdateorder() const |
181 |
|
{ // return date order |
182 |
|
return ::_Getdateorder(); |
183 |
|
} |
184 |
|
|
185 |
|
private: |
186 |
|
#ifdef _M_CEE |
187 |
|
// in managed code we need to manually take the lock; |
188 |
|
// we use an empty structure to mantain the same size |
189 |
|
_EmptyLockit _Empty_lock; |
190 |
|
#else |
191 |
|
_Lockit _Lock; // thread lock, because global locale is altered |
192 |
|
#endif |
193 |
|
string _Days; // weekday names |
194 |
|
string _Months; // month names |
195 |
|
string _Oldlocname; // old locale name to revert to on destruction |
196 |
|
string _Newlocname; // new locale name for this object |
197 |
|
}; |
198 |
|
#pragma warning(pop) |
199 |
|
|
200 |
|
// TEMPLATE FUNCTION _LStrcoll |
201 |
|
template<class _Elem> inline |
202 |
|
int __CRTDECL _LStrcoll(const _Elem *_First1, const _Elem *_Last1, |
203 |
|
const _Elem *_First2, const _Elem *_Last2, |
204 |
|
const _Locinfo::_Collvec *) |
205 |
|
{ // perform locale-specific comparison of _Elem sequences |
206 |
|
for (; _First1 != _Last1 && _First2 != _Last2; ++_First1, ++_First2) |
207 |
|
if (*_First1 < *_First2) |
208 |
|
return (-1); // [_First1, _Last1) < [_First2, _Last2) |
209 |
|
else if (*_First2 < *_First1) |
210 |
|
return (+1); // [_First1, _Last1) > [_First2, _Last2) |
211 |
|
return (_First2 != _Last2 ? -1 : _First1 != _Last1 ? +1 : 0); |
212 |
|
} |
213 |
|
|
214 |
|
template<> inline |
215 |
|
int __CRTDECL _LStrcoll(const char *_First1, const char *_Last1, |
216 |
|
const char *_First2, const char *_Last2, |
217 |
|
const _Locinfo::_Collvec *_Vector) |
218 |
|
{ // perform locale-specific comparison of char sequences |
219 |
|
return (_Strcoll(_First1, _Last1, _First2, _Last2, _Vector)); |
220 |
|
} |
221 |
|
|
222 |
|
template<> inline |
223 |
|
int __CRTDECL _LStrcoll(const wchar_t *_First1, const wchar_t *_Last1, |
224 |
|
const wchar_t *_First2, const wchar_t *_Last2, |
225 |
|
const _Locinfo::_Collvec *_Vector) |
226 |
|
{ // perform locale-specific comparison of wchar_t sequences |
227 |
|
return (_Wcscoll(_First1, _Last1, _First2, _Last2, _Vector)); |
228 |
|
} |
229 |
|
|
230 |
|
// TEMPLATE FUNCTION _LStrxfrm |
231 |
|
template<class _Elem> inline |
232 |
|
size_t __CRTDECL _LStrxfrm(_Elem *_First1, _Elem *_Last1, |
233 |
|
const _Elem *_First2, const _Elem *_Last2, |
234 |
|
const _Locinfo::_Collvec *) |
235 |
|
{ // perform locale-specific transform of _Elems [_First1, _Last1) |
236 |
|
size_t _Count = _Last2 - _First2; |
237 |
|
if (_Count <= (size_t)(_Last1 - _First1)) |
238 |
|
_CRT_SECURE_MEMCPY(_First1, (_Last1 - _First1)* sizeof(_Elem), _First2, _Count * sizeof (_Elem)); |
239 |
|
return (_Count); |
240 |
|
} |
241 |
|
|
242 |
|
template<> inline |
243 |
|
size_t __CRTDECL _LStrxfrm( |
244 |
|
_Out_cap_x_(_Last1-_First1) _Post_count_( return) char *_First1, |
245 |
|
_In_z_ char *_Last1, |
246 |
|
const char *_First2, const char *_Last2, |
247 |
|
const _Locinfo::_Collvec *_Vector) |
248 |
|
{ // perform locale-specific transform of chars [_First1, _Last1) |
249 |
|
return (_Strxfrm(_First1, _Last1, _First2, _Last2, _Vector)); |
250 |
|
} |
251 |
|
|
252 |
|
template<> inline |
253 |
|
size_t __CRTDECL _LStrxfrm( |
254 |
|
_Out_cap_x_(_Last1-_First1) _Post_count_( return) wchar_t *_First1, |
255 |
|
_In_z_ wchar_t *_Last1, |
256 |
|
const wchar_t *_First2, const wchar_t *_Last2, |
257 |
|
const _Locinfo::_Collvec *_Vector) |
258 |
|
{ // perform locale-specific transform of wchar_ts [_First1, _Last1) |
259 |
|
return (_Wcsxfrm(_First1, _Last1, _First2, _Last2, _Vector)); |
260 |
|
} |
261 |
|
_STD_END |
262 |
|
#ifdef _MSC_VER |
263 |
|
#pragma warning(pop) |
264 |
|
#pragma pack(pop) |
265 |
|
#endif /* _MSC_VER */ |
266 |
|
|
267 |
|
#endif /* RC_INVOKED */ |
268 |
|
#endif /* _XLOCINFO_ */ |
269 |
|
|
270 |
|
/* |
271 |
|
* Copyright (c) 1992-2007 by P.J. Plauger. ALL RIGHTS RESERVED. |
272 |
|
* Consult your license regarding permissions and restrictions. |
273 |
|
V5.03:0009 */ |
274 |
|
|
|
|
|