Source code of Windows XP (NT5)
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.

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