Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

639 lines
26 KiB

  1. // xlocale internal header (from <locale>)
  2. #ifndef _XLOCALE_
  3. #define _XLOCALE_
  4. #include <climits>
  5. #include <cstring>
  6. #include <stdexcept>
  7. #include <typeinfo>
  8. #include <xlocinfo>
  9. #ifdef _MSC_VER
  10. #pragma pack(push,8)
  11. #endif /* _MSC_VER */
  12. _STD_BEGIN
  13. // CLASS locale
  14. class _CRTIMP locale {
  15. public:
  16. enum _Category {collate = _M_COLLATE, ctype = _M_CTYPE,
  17. monetary = _M_MONETARY, numeric = _M_NUMERIC,
  18. time = _M_TIME, messages = _M_MESSAGE,
  19. all = _M_ALL, none = 0};
  20. typedef int category;
  21. // CLASS id
  22. class _CRTIMP id {
  23. public:
  24. operator size_t()
  25. {_Lockit _Lk;
  26. if (_Id == 0)
  27. _Id = ++_Id_cnt;
  28. return (_Id); }
  29. private:
  30. size_t _Id;
  31. static int _Id_cnt;
  32. };
  33. class _Locimp;
  34. // class facet
  35. class _CRTIMP facet {
  36. friend class locale;
  37. friend class _Locimp;
  38. public:
  39. static size_t __cdecl _Getcat()
  40. {return ((size_t)(-1)); }
  41. void _Incref()
  42. {_Lockit _Lk;
  43. if (_Refs < (size_t)(-1))
  44. ++_Refs; }
  45. facet *_Decref()
  46. {_Lockit _Lk;
  47. if (0 < _Refs && _Refs < (size_t)(-1))
  48. --_Refs;
  49. return (_Refs == 0 ? this : 0); }
  50. _PROTECTED:
  51. virtual ~facet()
  52. {}
  53. protected:
  54. explicit facet(size_t _R = 0)
  55. : _Refs(_R) {}
  56. private:
  57. facet(const facet&); // undefined
  58. const facet& operator=(const facet&); // undefined
  59. size_t _Refs;
  60. };
  61. // CLASS _Locimp
  62. class _Locimp : public facet {
  63. _PROTECTED:
  64. ~_Locimp();
  65. private:
  66. friend class locale;
  67. _Locimp(bool _Xp = false);
  68. _Locimp(const _Locimp&);
  69. void _Addfac(facet *, size_t);
  70. static _Locimp *__cdecl _Makeloc(const _Locinfo&,
  71. category, _Locimp *, const locale *);
  72. static void __cdecl _Makewloc(const _Locinfo&,
  73. category, _Locimp *, const locale *);
  74. static void __cdecl _Makexloc(const _Locinfo&,
  75. category, _Locimp *, const locale *);
  76. facet **_Fv;
  77. size_t _Nfv;
  78. category _Cat;
  79. bool _Xpar;
  80. string _Name;
  81. static _CRTIMP _Locimp *_Clocptr, *_Global;
  82. };
  83. locale& _Addfac(facet *, size_t, size_t);
  84. bool operator()(const string&, const string&) const;
  85. locale() _THROW0()
  86. : _Ptr(_Init())
  87. {_Lockit _lk;
  88. _Locimp::_Global->_Incref(); }
  89. locale(_Uninitialized)
  90. {}
  91. locale(const locale& _X) _THROW0()
  92. : _Ptr(_X._Ptr)
  93. {_Ptr->_Incref(); }
  94. locale(const locale&, const locale&, category);
  95. explicit locale(const char *, category = all);
  96. locale(const locale&, const char *, category);
  97. ~locale() _THROW0()
  98. {if (_Ptr != 0)
  99. delete _Ptr->_Decref(); }
  100. locale& operator=(const locale& _X) _THROW0()
  101. {if (_Ptr != _X._Ptr)
  102. {delete _Ptr->_Decref();
  103. _Ptr = _X._Ptr;
  104. _Ptr->_Incref(); }
  105. return (*this); }
  106. string name() const
  107. {return (_Ptr->_Name); }
  108. const facet *_Getfacet(size_t _Id, bool _Xp = false) const;
  109. bool _Iscloc() const;
  110. bool operator==(const locale& _X) const;
  111. bool operator!=(const locale& _X) const
  112. {return (!(*this == _X)); }
  113. static const locale& __cdecl classic();
  114. static locale __cdecl global(const locale&);
  115. static locale __cdecl empty();
  116. private:
  117. locale(_Locimp *_P)
  118. : _Ptr(_P) {}
  119. static _Locimp *__cdecl _Init();
  120. static void __cdecl _Tidy();
  121. _Locimp *_Ptr;
  122. };
  123. _BITMASK_OPS(locale::_Category);
  124. // SUPPORT TEMPLATES
  125. template<class _F>
  126. class _Tidyfac {
  127. public:
  128. static _F *__cdecl _Save(_F *_Fac)
  129. {_Lockit _Lk;
  130. _Facsav = _Fac;
  131. _Facsav->_Incref();
  132. atexit(_Tidy);
  133. return (_Fac); }
  134. static void __cdecl _Tidy()
  135. {_Lockit _Lk;
  136. delete _Facsav->_Decref();
  137. _Facsav = 0; }
  138. private:
  139. static _F *_Facsav;
  140. };
  141. template<class _F>
  142. _F *_Tidyfac<_F>::_Facsav = 0;
  143. #define _ADDFAC(loc, pfac) _Addfac(loc, pfac)
  144. #define _USEFAC(loc, fac) use_facet(loc, (fac *)0, false)
  145. #define _USE(loc, fac) use_facet(loc, (fac *)0, true)
  146. template<class _F> inline
  147. locale _Addfac(locale _X, _F *_Fac)
  148. {_Lockit _Lk;
  149. return (_X._Addfac(_Fac, _F::id, _F::_Getcat())); }
  150. template<class _F> inline
  151. const _F& __cdecl use_facet(const locale& _L, const _F *,
  152. bool _Cfacet)
  153. {static const locale::facet *_Psave = 0;
  154. _Lockit _Lk;
  155. size_t _Id = _F::id;
  156. const locale::facet *_Pf = _L._Getfacet(_Id, true);
  157. if (_Pf != 0)
  158. ;
  159. else if (!_Cfacet || !_L._Iscloc())
  160. _THROW(bad_cast, "missing locale facet");
  161. else if (_Psave == 0)
  162. _Pf = _Psave = _Tidyfac<_F>::_Save(new _F);
  163. else
  164. _Pf = _Psave;
  165. return (*(const _F *)_Pf); }
  166. // TEMPLATE FUNCTION _Narrow
  167. #define _NARROW(T, V) _Narrow((T)(V))
  168. template<class _E> inline
  169. int _Narrow(_E _C) // needs _E::operator char()
  170. {return ((unsigned char)(char)_C); }
  171. inline int _Narrow(wchar_t _C)
  172. {return (wctob(_C)); }
  173. // TEMPLATE FUNCTION _Widen
  174. #define _WIDEN(T, V) _Widen(V, (T *)0)
  175. template<class _E> inline
  176. _E _Widen(char _Ch, _E *) // needs _E(char)
  177. {return (_Ch); }
  178. inline wchar_t _Widen(char _Ch, wchar_t *)
  179. {return (btowc(_Ch)); }
  180. // TEMPLATE FUNCTION _Getloctxt
  181. template<class _E, class _II> inline
  182. int __cdecl _Getloctxt(_II& _F, _II& _L, size_t _N,
  183. const _E *_S)
  184. {for (size_t _I = 0; _S[_I] != (_E)0; ++_I)
  185. if (_S[_I] == _S[0])
  186. ++_N;
  187. string _Str(_N, '\0');
  188. int _Ans = -2;
  189. for (size_t _J = 1; ; ++_J, ++_F, _Ans = -1)
  190. {bool _Pfx;
  191. size_t _I, _K;
  192. for (_I = 0, _K = 0, _Pfx = false; _K < _N; ++_K)
  193. {for (; _S[_I] != (_E)0 && _S[_I] != _S[0]; ++_I)
  194. ;
  195. if (_Str[_K] != '\0')
  196. _I += _Str[_K];
  197. else if (_S[_I += _J] == _S[0] || _S[_I] == (_E)0)
  198. {_Str[_K] = (char)(_J < 127 ? _J : 127);
  199. _Ans = (int)_K; }
  200. else if (_F == _L || _S[_I] != *_F)
  201. _Str[_K] = (char)(_J < 127 ? _J : 127);
  202. else
  203. _Pfx = true; }
  204. if (!_Pfx || _F == _L)
  205. break; }
  206. return (_Ans); }
  207. // TEMPLATE FUNCTION _Maklocstr
  208. #define _MAKLOCSTR(T, S) _Maklocstr(S, (T *)0)
  209. template<class _E> inline
  210. _E *__cdecl _Maklocstr(const char *_S, _E *)
  211. {size_t _L = strlen(_S) + 1;
  212. _E *_X = new _E[_L];
  213. for (_E *_P = _X; 0 < _L; --_L, ++_P, ++_S)
  214. *_P = _WIDEN(_E, *_S);
  215. return (_X); }
  216. // STRUCT codecvt_base
  217. class _CRTIMP codecvt_base : public locale::facet {
  218. public:
  219. enum _Result {ok, partial, error, noconv};
  220. _BITMASK(_Result, result);
  221. codecvt_base(size_t _R = 0)
  222. : locale::facet(_R) {}
  223. bool always_noconv() const _THROW0()
  224. {return (do_always_noconv()); }
  225. int max_length() const _THROW0()
  226. {return (do_max_length()); }
  227. int encoding() const _THROW0()
  228. {return (do_encoding()); }
  229. protected:
  230. virtual bool do_always_noconv() const _THROW0()
  231. {return (true); }
  232. virtual int do_max_length() const _THROW0()
  233. {return (1); }
  234. virtual int do_encoding() const _THROW0()
  235. {return (1); }
  236. };
  237. _BITMASK_OPS(codecvt_base::_Result);
  238. // TEMPLATE CLASS codecvt
  239. template<class _E, class _To, class _St>
  240. class codecvt : public codecvt_base {
  241. public:
  242. typedef _E from_type;
  243. typedef _To to_type;
  244. typedef _St state_type;
  245. result in(_St& _State,
  246. const _To *_F1, const _To *_L1, const _To *& _Mid1,
  247. _E *_F2, _E *_L2, _E *& _Mid2) const
  248. {return (do_in(_State,
  249. _F1, _L1, _Mid1, _F2, _L2, _Mid2)); }
  250. result out(_St& _State,
  251. const _E *_F1, const _E *_L1, const _E *& _Mid1,
  252. _To *_F2, _To *_L2, _To *& _Mid2) const
  253. {return (do_out(_State,
  254. _F1, _L1, _Mid1, _F2, _L2, _Mid2)); }
  255. int length(_St& _State, const _E *_F1,
  256. const _E *_L1, size_t _N2) const _THROW0()
  257. {return (do_length(_State, _F1, _L1, _N2)); }
  258. static locale::id id;
  259. explicit codecvt(size_t _R = 0)
  260. : codecvt_base(_R) {_Init(_Locinfo()); }
  261. codecvt(const _Locinfo& _Lobj, size_t _R = 0)
  262. : codecvt_base(_R) {_Init(_Lobj); }
  263. static size_t __cdecl _Getcat()
  264. {return (_LC_CTYPE); }
  265. _PROTECTED:
  266. virtual ~codecvt()
  267. {};
  268. protected:
  269. void _Init(const _Locinfo& _Lobj)
  270. {_Cvt = _Lobj._Getcvt(); }
  271. virtual result do_in(_St& _State,
  272. const _To *_F1, const _To *, const _To *& _Mid1,
  273. _E *_F2, _E *, _E *& _Mid2) const
  274. {(_State); _Mid1 = _F1, _Mid2 = _F2;
  275. return (noconv); }
  276. virtual result do_out(_St& _State,
  277. const _E *_F1, const _E *, const _E *& _Mid1,
  278. _To *_F2, _To *, _To *& _Mid2) const
  279. {(_State);_Mid1 = _F1, _Mid2 = _F2;
  280. return (noconv); }
  281. virtual int do_length(_St& _State, const _E *_F1,
  282. const _E *_L1, size_t _N2) const _THROW0()
  283. {(_State);return (int)(_N2 < (size_t)(_L1 - _F1) ? _N2 : (_L1 - _F1)); }
  284. private:
  285. _Locinfo::_Cvtvec _Cvt;
  286. };
  287. template<class _E, class _To, class _St>
  288. locale::id codecvt<_E, _To, _St>::id;
  289. // CLASS codecvt<wchar_t, char, mbstate_t>
  290. template <>
  291. class _CRTIMP codecvt<wchar_t, char, mbstate_t> : public codecvt_base {
  292. public:
  293. typedef wchar_t _E;
  294. typedef char _To;
  295. typedef mbstate_t _St;
  296. typedef _E from_type;
  297. typedef _To to_type;
  298. typedef _St state_type;
  299. result in(_St& _State,
  300. const _To *_F1, const _To *_L1, const _To *& _Mid1,
  301. _E *_F2, _E *_L2, _E *& _Mid2) const
  302. {return (do_in(_State,
  303. _F1, _L1, _Mid1, _F2, _L2, _Mid2)); }
  304. result out(_St& _State,
  305. const _E *_F1, const _E *_L1, const _E *& _Mid1,
  306. _To *_F2, _To *_L2, _To *& _Mid2) const
  307. {return (do_out(_State,
  308. _F1, _L1, _Mid1, _F2, _L2, _Mid2)); }
  309. int length(_St& _State, const _E *_F1,
  310. const _E *_L1, size_t _N2) const _THROW0()
  311. {return (do_length(_State, _F1, _L1, _N2)); }
  312. static locale::id id;
  313. explicit codecvt(size_t _R = 0)
  314. : codecvt_base(_R) {_Init(_Locinfo()); }
  315. codecvt(const _Locinfo& _Lobj, size_t _R = 0)
  316. : codecvt_base(_R) {_Init(_Lobj); }
  317. static size_t __cdecl _Getcat()
  318. {return (_LC_CTYPE); }
  319. _PROTECTED:
  320. virtual ~codecvt()
  321. {};
  322. protected:
  323. void _Init(const _Locinfo& _Lobj)
  324. {_Cvt = _Lobj._Getcvt(); }
  325. virtual result do_in(_St& _State,
  326. const _To *_F1, const _To *_L1, const _To *& _Mid1,
  327. _E *_F2, _E *_L2, _E *& _Mid2) const
  328. {_Mid1 = _F1, _Mid2 = _F2;
  329. result _Ans = _Mid1 == _L1 ? ok : partial;
  330. int _N;
  331. while (_Mid1 != _L1 && _Mid2 != _L2)
  332. switch (_N =
  333. _Mbrtowc(_Mid2, _Mid1, _L1 - _Mid1,
  334. &_State, &_Cvt))
  335. {case -2:
  336. _Mid1 = _L1;
  337. return (_Ans);
  338. case -1:
  339. return (error);
  340. case 0:
  341. _N = (int)strlen(_Mid1) + 1;
  342. default: // fall through
  343. _Mid1 += _N, ++_Mid2, _Ans = ok; }
  344. return (_Ans); }
  345. virtual result do_out(_St& _State,
  346. const _E *_F1, const _E *_L1, const _E *& _Mid1,
  347. _To *_F2, _To *_L2, _To *& _Mid2) const
  348. {_Mid1 = _F1, _Mid2 = _F2;
  349. result _Ans = _Mid1 == _L1 ? ok : partial;
  350. int _N;
  351. while (_Mid1 != _L1 && _Mid2 != _L2)
  352. if (MB_CUR_MAX <= _L2 - _Mid2)
  353. if ((_N =
  354. _Wcrtomb(_Mid2, *_Mid1, &_State,
  355. &_Cvt)) <= 0)
  356. return (error);
  357. else
  358. ++_Mid1, _Mid2 += _N, _Ans = ok;
  359. else
  360. {_To _Buf[MB_LEN_MAX];
  361. _St _Stsave = _State;
  362. if ((_N =
  363. _Wcrtomb(_Buf, *_Mid1, &_State,
  364. &_Cvt)) <= 0)
  365. return (error);
  366. else if (_L2 - _Mid2 < _N)
  367. {_State = _Stsave;
  368. return (_Ans); }
  369. else
  370. {memcpy(_Mid2, _Buf, _N);
  371. ++_Mid1, _Mid2 += _N, _Ans = ok; }}
  372. return (_Ans); }
  373. virtual int do_length(_St& _State, const _E *_F1,
  374. const _E *_L1, size_t _N2) const _THROW0()
  375. {const _E *_Mid1;
  376. _To _Buf[MB_LEN_MAX];
  377. int _N;
  378. for (_Mid1 = _F1; _Mid1 != _L1 && 0 < _N2;
  379. ++_Mid1, _N2 -= _N)
  380. if ((_N =
  381. _Wcrtomb(_Buf, *_Mid1, &_State, &_Cvt)) <= 0
  382. || _N2 < (size_t) _N)
  383. break;
  384. return ((int) (_Mid1 - _F1)); }
  385. virtual bool do_always_noconv() const _THROW0()
  386. {return (false); }
  387. virtual int do_max_length() const _THROW0()
  388. {return (MB_LEN_MAX); }
  389. virtual int do_encoding() const _THROW0()
  390. {return (0); }
  391. private:
  392. _Locinfo::_Cvtvec _Cvt;
  393. };
  394. // TEMPLATE CLASS codecvt_byname
  395. template<class _E, class _To, class _St>
  396. class codecvt_byname : public codecvt<_E, _To, _St> {
  397. public:
  398. explicit codecvt_byname(const char *_S, size_t _R = 0)
  399. : codecvt<_E, _To, _St>(_Locinfo(_S), _R) {}
  400. _PROTECTED:
  401. virtual ~codecvt_byname()
  402. {}
  403. };
  404. // STRUCT ctype_base
  405. struct _CRTIMP ctype_base : public locale::facet {
  406. enum _Mask {alnum = _DI|_LO|_UP|_XA, alpha = _LO|_UP|_XA,
  407. cntrl = _BB, digit = _DI, graph = _DI|_LO|_PU|_UP|_XA,
  408. lower = _LO, print = _DI|_LO|_PU|_SP|_UP|_XA|_XD,
  409. punct = _PU, space = _CN|_SP|_XS, upper = _UP,
  410. xdigit = _XD};
  411. // _BITMASK(_Mask, mask);
  412. typedef short mask; // to match <ctype.h>
  413. ctype_base(size_t _R = 0)
  414. : locale::facet(_R) {}
  415. };
  416. // TEMPLATE CLASS ctype
  417. template<class _E>
  418. class ctype : public ctype_base {
  419. public:
  420. typedef _E char_type;
  421. bool is(mask _M, _E _C) const
  422. {return (do_is(_M, _C)); }
  423. const _E *is(const _E *_F, const _E *_L, mask *_V) const
  424. {return (do_is(_F, _L, _V)); }
  425. const _E *scan_is(mask _M, const _E *_F,
  426. const _E *_L) const
  427. {return (do_scan_is(_M, _F, _L)); }
  428. const _E *scan_not(mask _M, const _E *_F,
  429. const _E *_L) const
  430. {return (do_scan_not(_M, _F, _L)); }
  431. _E tolower(_E _C) const
  432. {return (do_tolower(_C)); }
  433. const _E *tolower(_E *_F, const _E *_L) const
  434. {return (do_tolower(_F, _L)); }
  435. _E toupper(_E _C) const
  436. {return (do_toupper(_C)); }
  437. const _E *toupper(_E *_F, const _E *_L) const
  438. {return (do_toupper(_F, _L)); }
  439. _E widen(char _X) const
  440. {return (do_widen(_X)); }
  441. const char *widen(const char *_F, const char *_L,
  442. _E *_V) const
  443. {return (do_widen(_F, _L, _V)); }
  444. char narrow(_E _C, char _D = '\0') const
  445. {return (do_narrow(_C, _D)); }
  446. const _E *narrow(const _E *_F, const _E *_L, char _D,
  447. char *_V) const
  448. {return (do_narrow(_F, _L, _D, _V)); }
  449. static locale::id id;
  450. explicit ctype(size_t _R = 0)
  451. : ctype_base(_R) {_Init(_Locinfo()); }
  452. ctype(const _Locinfo& _Lobj, size_t _R = 0)
  453. : ctype_base(_R) {_Init(_Lobj); }
  454. static size_t __cdecl _Getcat()
  455. {return (_LC_CTYPE); }
  456. _PROTECTED:
  457. virtual ~ctype()
  458. {if (_Ctype._Delfl)
  459. free((void *)_Ctype._Table); }
  460. protected:
  461. void _Init(const _Locinfo& _Lobj)
  462. {_Ctype = _Lobj._Getctype(); }
  463. virtual bool do_is(mask _M, _E _C) const
  464. {return ((_Ctype._Table[narrow(_C)] & _M) != 0); }
  465. virtual const _E *do_is(const _E *_F, const _E *_L,
  466. mask *_V) const
  467. {for (; _F != _L; ++_F, ++_V)
  468. *_V = _Ctype._Table[narrow(*_F)];
  469. return (_F); }
  470. virtual const _E *do_scan_is(mask _M, const _E *_F,
  471. const _E *_L) const
  472. {for (; _F != _L && !is(_M, *_F); ++_F)
  473. ;
  474. return (_F); }
  475. virtual const _E *do_scan_not(mask _M, const _E *_F,
  476. const _E *_L) const
  477. {for (; _F != _L && is(_M, *_F); ++_F)
  478. ;
  479. return (_F); }
  480. virtual _E do_tolower(_E _C) const
  481. {return ((_E)widen((char)_Tolower(narrow(_C), &_Ctype))); }
  482. virtual const _E *do_tolower(_E *_F, const _E *_L) const
  483. {for (; _F != _L; ++_F)
  484. *_F = (_E)_Tolower(*_F, &_Ctype);
  485. return ((const _E *)_F); }
  486. virtual _E do_toupper(_E _C) const
  487. {return ((_E)widen((char)_Toupper(narrow(_C), &_Ctype))); }
  488. virtual const _E *do_toupper(_E *_F, const _E *_L) const
  489. {for (; _F != _L; ++_F)
  490. *_F = (_E)_Toupper(*_F, &_Ctype);
  491. return ((const _E *)_F); }
  492. virtual _E do_widen(char _X) const
  493. {return (_WIDEN(_E, _X)); }
  494. virtual const char *do_widen(const char *_F, const char *_L,
  495. _E *_V) const
  496. {for (; _F != _L; ++_F, ++_V)
  497. *_V = _WIDEN(_E, *_F);
  498. return (_F); }
  499. virtual char do_narrow(_E _C, char) const
  500. {return ((char)_NARROW(_E, _C)); }
  501. virtual const _E *do_narrow(const _E *_F, const _E *_L,
  502. char, char *_V) const
  503. {for (; _F != _L; ++_F, ++_V)
  504. *_V = (char)_NARROW(_E, *_F);
  505. return (_F); }
  506. private:
  507. _Locinfo::_Ctypevec _Ctype;
  508. };
  509. template<class _E>
  510. locale::id ctype<_E>::id;
  511. // CLASS ctype<char>
  512. template <>
  513. class _CRTIMP ctype<char> : public ctype_base {
  514. public:
  515. typedef char _E;
  516. typedef _E char_type;
  517. bool is(mask _M, _E _C) const
  518. {return ((_Ctype._Table[(unsigned char)_C] & _M) != 0); }
  519. const _E *is(const _E *_F, const _E *_L, mask *_V) const
  520. {for (; _F != _L; ++_F, ++_V)
  521. *_V = _Ctype._Table[(unsigned char)*_F];
  522. return (_F); }
  523. const _E *scan_is(mask _M, const _E *_F,
  524. const _E *_L) const
  525. {for (; _F != _L && !is(_M, *_F); ++_F)
  526. ;
  527. return (_F); }
  528. const _E *scan_not(mask _M, const _E *_F,
  529. const _E *_L) const
  530. {for (; _F != _L && is(_M, *_F); ++_F)
  531. ;
  532. return (_F); }
  533. _E tolower(_E _C) const
  534. {return (do_tolower(_C)); }
  535. const _E *tolower(_E *_F, const _E *_L) const
  536. {return (do_tolower(_F, _L)); }
  537. _E toupper(_E _C) const
  538. {return (do_toupper(_C)); }
  539. const _E *toupper(_E *_F, const _E *_L) const
  540. {return (do_toupper(_F, _L)); }
  541. _E widen(char _X) const
  542. {return (_X); }
  543. const _E *widen(const char *_F, const char *_L, _E *_V) const
  544. {memcpy(_V, _F, _L - _F);
  545. return (_L); }
  546. _E narrow(_E _C, char _D = '\0') const
  547. {(_D); return (_C); }
  548. const _E *narrow(const _E *_F, const _E *_L, char _D,
  549. char *_V) const
  550. {(_D);memcpy(_V, _F, _L - _F);
  551. return (_L); }
  552. static locale::id id;
  553. explicit ctype(const mask *_Tab = 0, bool _Df = false,
  554. size_t _R = 0)
  555. : ctype_base(_R)
  556. {_Lockit Lk;
  557. _Init(_Locinfo());
  558. if (_Ctype._Delfl)
  559. free((void *)_Ctype._Table), _Ctype._Delfl = false;
  560. if (_Tab == 0)
  561. _Ctype._Table = _Cltab;
  562. else
  563. _Ctype._Table = _Tab, _Ctype._Delfl = _Df; }
  564. ctype(const _Locinfo& _Lobj, size_t _R = 0)
  565. : ctype_base(_R) {_Init(_Lobj); }
  566. static size_t __cdecl _Getcat()
  567. {return (_LC_CTYPE); }
  568. static const size_t table_size;
  569. _PROTECTED:
  570. virtual ~ctype()
  571. {if (_Ctype._Delfl)
  572. free((void *)_Ctype._Table); }
  573. protected:
  574. static void __cdecl _Term(void)
  575. {free((void *)_Cltab); }
  576. void _Init(const _Locinfo& _Lobj)
  577. {_Lockit Lk;
  578. _Ctype = _Lobj._Getctype();
  579. if (_Cltab == 0)
  580. {_Cltab = _Ctype._Table;
  581. atexit(_Term);
  582. _Ctype._Delfl = false; }}
  583. virtual _E do_tolower(_E _C) const
  584. {return (_E)(_Tolower((unsigned char)_C, &_Ctype)); }
  585. virtual const _E *do_tolower(_E *_F, const _E *_L) const
  586. {for (; _F != _L; ++_F)
  587. *_F = (_E)_Tolower(*_F, &_Ctype);
  588. return ((const _E *)_F); }
  589. virtual _E do_toupper(_E _C) const
  590. {return ((_E)_Toupper((unsigned char)_C, &_Ctype)); }
  591. virtual const _E *do_toupper(_E *_F, const _E *_L) const
  592. {for (; _F != _L; ++_F)
  593. *_F = (_E)_Toupper(*_F, &_Ctype);
  594. return ((const _E *)_F); }
  595. const mask *table() const _THROW0()
  596. {return (_Ctype._Table); }
  597. static const mask * __cdecl classic_table() _THROW0()
  598. {_Lockit Lk;
  599. if (_Cltab == 0)
  600. locale::classic(); // force locale::_Init() call
  601. return (_Cltab); }
  602. private:
  603. _Locinfo::_Ctypevec _Ctype;
  604. static const mask *_Cltab;
  605. };
  606. // TEMPLATE CLASS ctype_byname
  607. template<class _E>
  608. class ctype_byname : public ctype<_E> {
  609. public:
  610. explicit ctype_byname(const char *_S, size_t _R = 0)
  611. : ctype<_E>(_Locinfo(_S), _R) {}
  612. _PROTECTED:
  613. virtual ~ctype_byname()
  614. {}
  615. };
  616. #ifdef _DLL
  617. #pragma warning(disable:4231) /* the extern before template is a non-standard extension */
  618. extern template class _CRTIMP ctype<wchar_t>;
  619. extern template class _CRTIMP codecvt<char, char, int>;
  620. #pragma warning(default:4231) /* restore previous warning */
  621. #endif // _DLL
  622. _STD_END
  623. #ifdef _MSC_VER
  624. #pragma pack(pop)
  625. #endif /* _MSC_VER */
  626. #endif /* _XLOCALE_ */
  627. /*
  628. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  629. * Consult your license regarding permissions and restrictions.
  630. */