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.

229 lines
7.0 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. #ifdef __FORCE_INSTANCE
  66. template class _CRTIMP2 collate<char>;
  67. template class _CRTIMP2 collate<wchar_t>;
  68. #else // __FORCE_INSTANCE
  69. #pragma warning(disable:4231) /* the extern before template is a non-standard extension */
  70. extern template class _CRTIMP2 collate<char>;
  71. extern template class _CRTIMP2 collate<wchar_t>;
  72. #pragma warning(default:4231) /* restore previous warning */
  73. #endif // __FORCE_INSTANCE
  74. #endif // _DLL
  75. template<class _E>
  76. locale::id collate<_E>::id;
  77. // TEMPLATE CLASS collate_byname
  78. template<class _E>
  79. class collate_byname : public collate<_E> {
  80. public:
  81. explicit collate_byname(const char *_S, size_t _R = 0)
  82. : collate<_E>(_Locinfo(_S), _R) {}
  83. _PROTECTED:
  84. virtual ~collate_byname()
  85. {}
  86. };
  87. // STRUCT messages_base
  88. struct _CRTIMP2 messages_base : public locale::facet {
  89. typedef int catalog;
  90. explicit messages_base(size_t _R = 0)
  91. : locale::facet(_R) {}
  92. };
  93. // TEMPLATE CLASS messages
  94. template<class _E>
  95. class messages : public messages_base {
  96. public:
  97. typedef _E char_type;
  98. typedef basic_string<_E, char_traits<_E>,
  99. allocator<_E> > string_type;
  100. catalog open(const string& _X, const locale& _L) const
  101. {return (do_open(_X, _L)); }
  102. string_type get(catalog _C, int _S, int _M,
  103. const string_type& _D) const
  104. {return (do_get(_C, _S, _M, _D)); }
  105. void close(catalog _C) const
  106. {do_close(_C); }
  107. static locale::id id;
  108. explicit messages(size_t _R = 0)
  109. : messages_base(_R) {_Init(_Locinfo()); }
  110. messages(const _Locinfo& _Lobj, size_t _R = 0)
  111. : messages_base(_R) {_Init(_Lobj); }
  112. static size_t __cdecl _Getcat()
  113. {return (_LC_MESSAGE); }
  114. _PROTECTED:
  115. ~messages()
  116. {delete[] _No;
  117. delete[] _Yes; }
  118. protected:
  119. void _Init(const _Locinfo& _Lobj)
  120. {_No = _MAKLOCSTR(_E, _Lobj._Getno());
  121. _Yes = _MAKLOCSTR(_E, _Lobj._Getyes()); }
  122. virtual catalog do_open(const string&, const locale&) const
  123. {return (0); }
  124. virtual string_type do_get(catalog, int,
  125. int _M, const string_type& _D) const
  126. {if (_M == 0)
  127. return (_No);
  128. else if (_M == 1)
  129. return (_Yes);
  130. else
  131. return (_D); }
  132. virtual void do_close(catalog) const
  133. {}
  134. private:
  135. _E *_No, *_Yes;
  136. };
  137. #ifdef _DLL
  138. #ifdef __FORCE_INSTANCE
  139. template class _CRTIMP2 messages<char>;
  140. template class _CRTIMP2 messages<wchar_t>;
  141. #else // __FORCE_INSTANCE
  142. #pragma warning(disable:4231) /* the extern before template is a non-standard extension */
  143. extern template class _CRTIMP2 messages<char>;
  144. extern template class _CRTIMP2 messages<wchar_t>;
  145. #pragma warning(default:4231) /* restore previous warning */
  146. #endif // __FORCE_INSTANCE
  147. #endif // _DLL
  148. template<class _E>
  149. locale::id messages<_E>::id;
  150. // TEMPLATE CLASS messages_byname
  151. template<class _E>
  152. class messages_byname : public messages<_E> {
  153. public:
  154. explicit messages_byname(const char *_S, size_t _R = 0)
  155. : messages<_E>(_Locinfo(_S), _R) {}
  156. _PROTECTED:
  157. virtual ~messages_byname()
  158. {}
  159. };
  160. // locale SUPPORT TEMPLATES
  161. #define _HAS(loc, fac) has_facet(loc, (fac *)0)
  162. template<class _F> inline
  163. bool has_facet(const locale& _L, const _F *) // _THROW0()
  164. {size_t _Id = _F::id;
  165. const locale::facet *_Pf = (_F *)0;
  166. return (_L._Getfacet(_Id) != 0
  167. || _L._Iscloc() && _F::_Getcat() != (size_t)(-1)); }
  168. typedef collate<char> _Collchar;
  169. inline bool locale::operator()(const string& _X,
  170. const string& _Y) const
  171. {const _Collchar& _Fac = _USE(*this, _Collchar);
  172. return (_Fac.compare(_X.begin(), _X.end(),
  173. _Y.begin(), _Y.end()) < 0); }
  174. // ctype TEMPLATE FUNCTIONS
  175. template<class _E> inline
  176. bool (isalnum)(_E _C, const locale& _L)
  177. {return (_USE(_L, ctype<_E>).is(ctype_base::alnum, _C)); }
  178. template<class _E> inline
  179. bool (isalpha)(_E _C, const locale& _L)
  180. {return (_USE(_L, ctype<_E>).is(ctype_base::alpha, _C)); }
  181. template<class _E> inline
  182. bool (iscntrl)(_E _C, const locale& _L)
  183. {return (_USE(_L, ctype<_E>).is(ctype_base::cntrl, _C)); }
  184. template<class _E> inline
  185. bool (isgraph)(_E _C, const locale& _L)
  186. {return (_USE(_L, ctype<_E>).is(ctype_base::graph, _C)); }
  187. template<class _E> inline
  188. bool (islower)(_E _C, const locale& _L)
  189. {return (_USE(_L, ctype<_E>).is(ctype_base::lower, _C)); }
  190. template<class _E> inline
  191. bool (isprint)(_E _C, const locale& _L)
  192. {return (_USE(_L, ctype<_E>).is(ctype_base::print, _C)); }
  193. template<class _E> inline
  194. bool (ispunct)(_E _C, const locale& _L)
  195. {return (_USE(_L, ctype<_E>).is(ctype_base::punct, _C)); }
  196. template<class _E> inline
  197. bool (isspace)(_E _C, const locale& _L)
  198. {return (_USE(_L, ctype<_E>).is(ctype_base::space, _C)); }
  199. template<class _E> inline
  200. bool (isupper)(_E _C, const locale& _L)
  201. {return (_USE(_L, ctype<_E>).is(ctype_base::upper, _C)); }
  202. template<class _E> inline
  203. bool (isxdigit)(_E _C, const locale& _L)
  204. {return (_USE(_L, ctype<_E>).is(ctype_base::xdigit, _C)); }
  205. template<class _E> inline
  206. _E (tolower)(_E _C, const locale& _L)
  207. {return (_USE(_L, ctype<_E>).tolower(_C)); }
  208. template<class _E> inline
  209. _E (toupper)(_E _C, const locale& _L)
  210. {return (_USE(_L, ctype<_E>).toupper(_C)); }
  211. _STD_END
  212. #ifdef _MSC_VER
  213. #pragma warning(pop)
  214. #pragma pack(pop)
  215. #endif /* _MSC_VER */
  216. #endif /* _LOCALE_ */
  217. /*
  218. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  219. * Consult your license regarding permissions and restrictions.
  220. */