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.

219 lines
6.7 KiB

  1. // locale standard header
  2. #ifndef _LOCALE_
  3. #define _LOCALE_
  4. #include <string>
  5. #include <xlocmon>
  6. #include <xlocnum>
  7. #include <xloctime>
  8. #ifdef _MSC_VER
  9. #pragma pack(push,8)
  10. #pragma warning(push,3)
  11. #pragma warning(disable:4675)
  12. #endif /* _MSC_VER */
  13. _STD_BEGIN
  14. // TEMPLATE CLASS collate
  15. template<class _E>
  16. class collate : public locale::facet {
  17. public:
  18. typedef _E char_type;
  19. typedef basic_string<_E, char_traits<_E>,
  20. allocator<_E> > string_type;
  21. int compare(const _E *_F1, const _E *_L1,
  22. const _E *_F2, const _E *_L2) const
  23. {return (do_compare(_F1, _L1, _F2, _L2)); }
  24. string_type transform(const _E *_F, const _E *_L) const
  25. {return (do_transform(_F, _L)); }
  26. long hash(const _E *_F, const _E *_L) const
  27. {return (do_hash(_F, _L)); }
  28. static locale::id id;
  29. explicit collate(size_t _R = 0)
  30. : locale::facet(_R) {_Init(_Locinfo()); }
  31. collate(const _Locinfo& _Lobj, size_t _R = 0)
  32. : locale::facet(_R) {_Init(_Lobj); }
  33. static size_t __cdecl _Getcat()
  34. {return (_LC_COLLATE); }
  35. _PROTECTED:
  36. ~collate()
  37. {}
  38. protected:
  39. void _Init(const _Locinfo& _Lobj)
  40. {_Coll = _Lobj._Getcoll(); }
  41. virtual int do_compare(const _E *_F1, const _E *_L1,
  42. const _E *_F2, const _E *_L2) const
  43. {return (_Strcoll(_F1, _L1, _F2, _L2, &_Coll)); }
  44. virtual string_type do_transform(const _E *_F,
  45. const _E *_L) const
  46. {size_t _I, _N;
  47. string_type _Str;
  48. for (_N = _L - _F; ; )
  49. {_Str.append(_N, '\0');
  50. if ((_I = _Strxfrm(_Str.begin(), _Str.end(),
  51. _F, _L, &_Coll)) <= _Str.size())
  52. break;
  53. _N = _Str.size() < _I ? _I - _Str.size() : 1; }
  54. _Str.resize(_I);
  55. return (_Str); }
  56. virtual long do_hash(const _E *_F, const _E *_L) const
  57. {unsigned long _V = 0;
  58. for (; _F != _L; ++_F)
  59. _V = (_V << 8 | _V >> 24) + *_F;
  60. return ((long)_V); }
  61. private:
  62. _Locinfo::_Collvec _Coll;
  63. };
  64. #ifdef _DLL
  65. #pragma warning(disable:4231) /* the extern before template is a non-standard extension */
  66. extern template class _CRTIMP collate<char>;
  67. extern template class _CRTIMP collate<wchar_t>;
  68. #pragma warning(default:4231) /* restore previous warning */
  69. #endif // _DLL
  70. template<class _E>
  71. locale::id collate<_E>::id;
  72. // TEMPLATE CLASS collate_byname
  73. template<class _E>
  74. class collate_byname : public collate<_E> {
  75. public:
  76. explicit collate_byname(const char *_S, size_t _R = 0)
  77. : collate<_E>(_Locinfo(_S), _R) {}
  78. _PROTECTED:
  79. virtual ~collate_byname()
  80. {}
  81. };
  82. // STRUCT messages_base
  83. struct _CRTIMP messages_base : public locale::facet {
  84. typedef int catalog;
  85. explicit messages_base(size_t _R = 0)
  86. : locale::facet(_R) {}
  87. };
  88. // TEMPLATE CLASS messages
  89. template<class _E>
  90. class messages : public messages_base {
  91. public:
  92. typedef _E char_type;
  93. typedef basic_string<_E, char_traits<_E>,
  94. allocator<_E> > string_type;
  95. catalog open(const string& _X, const locale& _L) const
  96. {return (do_open(_X, _L)); }
  97. string_type get(catalog _C, int _S, int _M,
  98. const string_type& _D) const
  99. {return (do_get(_C, _S, _M, _D)); }
  100. void close(catalog _C) const
  101. {do_close(_C); }
  102. static locale::id id;
  103. explicit messages(size_t _R = 0)
  104. : messages_base(_R) {_Init(_Locinfo()); }
  105. messages(const _Locinfo& _Lobj, size_t _R = 0)
  106. : messages_base(_R) {_Init(_Lobj); }
  107. static size_t __cdecl _Getcat()
  108. {return (_LC_MESSAGE); }
  109. _PROTECTED:
  110. ~messages()
  111. {delete[] _No;
  112. delete[] _Yes; }
  113. protected:
  114. void _Init(const _Locinfo& _Lobj)
  115. {_No = _MAKLOCSTR(_E, _Lobj._Getno());
  116. _Yes = _MAKLOCSTR(_E, _Lobj._Getyes()); }
  117. virtual catalog do_open(const string&, const locale&) const
  118. {return (0); }
  119. virtual string_type do_get(catalog, int,
  120. int _M, const string_type& _D) const
  121. {if (_M == 0)
  122. return (_No);
  123. else if (_M == 1)
  124. return (_Yes);
  125. else
  126. return (_D); }
  127. virtual void do_close(catalog) const
  128. {}
  129. private:
  130. _E *_No, *_Yes;
  131. };
  132. #ifdef _DLL
  133. #pragma warning(disable:4231) /* the extern before template is a non-standard extension */
  134. extern template class _CRTIMP messages<char>;
  135. extern template class _CRTIMP messages<wchar_t>;
  136. #pragma warning(default:4231) /* restore previous warning */
  137. #endif // _DLL
  138. template<class _E>
  139. locale::id messages<_E>::id;
  140. // TEMPLATE CLASS messages_byname
  141. template<class _E>
  142. class messages_byname : public messages<_E> {
  143. public:
  144. explicit messages_byname(const char *_S, size_t _R = 0)
  145. : messages<_E>(_Locinfo(_S), _R) {}
  146. _PROTECTED:
  147. virtual ~messages_byname()
  148. {}
  149. };
  150. // locale SUPPORT TEMPLATES
  151. #define _HAS(loc, fac) has_facet(loc, (fac *)0)
  152. template<class _F> inline
  153. bool has_facet(const locale& _L, const _F *) // _THROW0()
  154. {size_t _Id = _F::id;
  155. const locale::facet *_Pf = (_F *)0;
  156. return (_L._Getfacet(_Id) != 0
  157. || _L._Iscloc() && _F::_Getcat() != (size_t)(-1)); }
  158. typedef collate<char> _Collchar;
  159. inline bool locale::operator()(const string& _X,
  160. const string& _Y) const
  161. {const _Collchar& _Fac = _USE(*this, _Collchar);
  162. return (_Fac.compare(_X.begin(), _X.end(),
  163. _Y.begin(), _Y.end()) < 0); }
  164. // ctype TEMPLATE FUNCTIONS
  165. template<class _E> inline
  166. bool (isalnum)(_E _C, const locale& _L)
  167. {return (_USE(_L, ctype<_E>).is(ctype_base::alnum, _C)); }
  168. template<class _E> inline
  169. bool (isalpha)(_E _C, const locale& _L)
  170. {return (_USE(_L, ctype<_E>).is(ctype_base::alpha, _C)); }
  171. template<class _E> inline
  172. bool (iscntrl)(_E _C, const locale& _L)
  173. {return (_USE(_L, ctype<_E>).is(ctype_base::cntrl, _C)); }
  174. template<class _E> inline
  175. bool (isgraph)(_E _C, const locale& _L)
  176. {return (_USE(_L, ctype<_E>).is(ctype_base::graph, _C)); }
  177. template<class _E> inline
  178. bool (islower)(_E _C, const locale& _L)
  179. {return (_USE(_L, ctype<_E>).is(ctype_base::lower, _C)); }
  180. template<class _E> inline
  181. bool (isprint)(_E _C, const locale& _L)
  182. {return (_USE(_L, ctype<_E>).is(ctype_base::print, _C)); }
  183. template<class _E> inline
  184. bool (ispunct)(_E _C, const locale& _L)
  185. {return (_USE(_L, ctype<_E>).is(ctype_base::punct, _C)); }
  186. template<class _E> inline
  187. bool (isspace)(_E _C, const locale& _L)
  188. {return (_USE(_L, ctype<_E>).is(ctype_base::space, _C)); }
  189. template<class _E> inline
  190. bool (isupper)(_E _C, const locale& _L)
  191. {return (_USE(_L, ctype<_E>).is(ctype_base::upper, _C)); }
  192. template<class _E> inline
  193. bool (isxdigit)(_E _C, const locale& _L)
  194. {return (_USE(_L, ctype<_E>).is(ctype_base::xdigit, _C)); }
  195. template<class _E> inline
  196. _E (tolower)(_E _C, const locale& _L)
  197. {return (_USE(_L, ctype<_E>).tolower(_C)); }
  198. template<class _E> inline
  199. _E (toupper)(_E _C, const locale& _L)
  200. {return (_USE(_L, ctype<_E>).toupper(_C)); }
  201. _STD_END
  202. #ifdef _MSC_VER
  203. #pragma warning(pop)
  204. #pragma pack(pop)
  205. #endif /* _MSC_VER */
  206. #endif /* _LOCALE_ */
  207. /*
  208. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  209. * Consult your license regarding permissions and restrictions.
  210. */