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.

212 lines
5.5 KiB

  1. // xlocinfo internal header for Microsoft
  2. #pragma once
  3. #ifndef _XLOCINFO_
  4. #define _XLOCINFO_
  5. #include <xlocinfo.h>
  6. #include <cstdlib>
  7. #include <xstddef>
  8. #pragma pack(push,8)
  9. #pragma warning(push,3)
  10. _STD_BEGIN
  11. // CLASS _Timevec
  12. class _CRTIMP2 _Timevec
  13. { // smart pointer to information used by _Strftime
  14. public:
  15. _Timevec(void *_Ptr = 0)
  16. : _Timeptr(_Ptr)
  17. { // construct from ptr
  18. }
  19. _Timevec(const _Timevec& _Right)
  20. { // construct from _Right
  21. *this = _Right;
  22. }
  23. ~_Timevec()
  24. { // destroy the object
  25. free(_Timeptr);
  26. }
  27. _Timevec& operator=(const _Timevec& _Right)
  28. { // transfer ownership of _Timeptr from _Right
  29. _Timeptr = _Right._Timeptr;
  30. ((_Timevec *)&_Right)->_Timeptr = 0;
  31. return (*this);
  32. }
  33. void *_Getptr() const
  34. { // return pointer to time information
  35. return (_Timeptr);
  36. }
  37. private:
  38. void *_Timeptr; // pointer to time information
  39. };
  40. // CLASS _Locinfo
  41. class _CRTIMP2 _Locinfo
  42. { // summary of all stuff peculiar to a locale used by standard facets
  43. public:
  44. typedef ::_Collvec _Collvec;
  45. typedef ::_Ctypevec _Ctypevec;
  46. typedef ::_Cvtvec _Cvtvec;
  47. typedef std::_Timevec _Timevec;
  48. _Locinfo(const char * = "C"); // construct from named locale
  49. _Locinfo(int, const char *); // construct from category
  50. ~_Locinfo(); // destroy the object
  51. _Locinfo& _Addcats(int, const char *); // add stuff for a category
  52. string _Getname() const
  53. { // return the new locale name
  54. return (_Newlocname);
  55. }
  56. _Collvec _Getcoll() const
  57. { // return collation stuff
  58. return (::_Getcoll());
  59. }
  60. _Ctypevec _Getctype() const
  61. { // return ctype stuff
  62. return (::_Getctype());
  63. }
  64. _Cvtvec _Getcvt() const
  65. { // return codecvt stuff
  66. return (::_Getcvt());
  67. }
  68. const lconv *_Getlconv() const
  69. { // return localeconv stuff
  70. return (localeconv());
  71. }
  72. _Timevec _Gettnames() const
  73. { // return names used by _Strftime
  74. return (_Timevec(::_Gettnames()));
  75. }
  76. const char *_Getdays() const
  77. { // return names for weekdays
  78. const char *_Ptr = ::_Getdays();
  79. if (_Ptr != 0)
  80. { // capture names and free allocated C string
  81. ((_Locinfo *)this)->_Days = _Ptr;
  82. free((void *)_Ptr);
  83. }
  84. return (_Days.size() != 0 ? _Days.c_str()
  85. : ":Sun:Sunday:Mon:Monday:Tue:Tuesday:Wed:Wednesday"
  86. ":Thu:Thursday:Fri:Friday:Sat:Saturday");
  87. }
  88. const char *_Getmonths() const
  89. { // return names for months
  90. const char *_Ptr = ::_Getmonths();
  91. if (_Ptr != 0)
  92. { // capture names and free allocated C string
  93. ((_Locinfo *)this)->_Months = _Ptr;
  94. free((void *)_Ptr);
  95. }
  96. return (_Months.size() != 0 ? _Months.c_str()
  97. : ":Jan:January:Feb:February:Mar:March"
  98. ":Apr:April:May:May:Jun:June"
  99. ":Jul:July:Aug:August:Sep:September"
  100. ":Oct:October:Nov:November:Dec:December");
  101. }
  102. const char *_Getfalse() const
  103. { // return false name (no C source)
  104. return ("false");
  105. }
  106. const char *_Gettrue() const
  107. { // return true name (no C source)
  108. return ("true");
  109. }
  110. int _Getdateorder() const
  111. { // return date order
  112. return ::_Getdateorder();
  113. }
  114. private:
  115. _Lockit _Lock; // thread lock, because global locale is altered
  116. string _Days; // weekday names
  117. string _Months; // month names
  118. string _Oldlocname; // old locale name to revert to on destruction
  119. string _Newlocname; // new locale name for this object
  120. };
  121. // TEMPLATE FUNCTION _LStrcoll
  122. template<class _Elem> inline
  123. int __cdecl _LStrcoll(const _Elem *_First1, const _Elem *_Last1,
  124. const _Elem *_First2, const _Elem *_Last2,
  125. const _Locinfo::_Collvec *)
  126. { // perform locale-specific comparison of _Elem sequences
  127. for (; _First1 != _Last1 && _First2 != _Last2; ++_First1, ++_First2)
  128. if (*_First1 < *_First2)
  129. return (-1); // [_First1, _Last1) < [_First2, _Last2)
  130. else if (*_First2 < *_First1)
  131. return (+1); // [_First1, _Last1) > [_First2, _Last2)
  132. return (_First2 != _Last2 ? -1 : _First1 != _Last1 ? +1 : 0);
  133. }
  134. template<> inline
  135. int __cdecl _LStrcoll(const char *_First1, const char *_Last1,
  136. const char *_First2, const char *_Last2,
  137. const _Locinfo::_Collvec *_Vector)
  138. { // perform locale-specific comparison of char sequences
  139. return (_Strcoll(_First1, _Last1, _First2, _Last2, _Vector));
  140. }
  141. template<> inline
  142. int __cdecl _LStrcoll(const wchar_t *_First1, const wchar_t *_Last1,
  143. const wchar_t *_First2, const wchar_t *_Last2,
  144. const _Locinfo::_Collvec *_Vector)
  145. { // perform locale-specific comparison of wchar_t sequences
  146. return (_Wcscoll(_First1, _Last1, _First2, _Last2, _Vector));
  147. }
  148. // TEMPLATE FUNCTION _LStrxfrm
  149. template<class _Elem> inline
  150. size_t __cdecl _LStrxfrm(_Elem *_First1, _Elem *_Last1,
  151. const _Elem *_First2, const _Elem *_Last2,
  152. const _Locinfo::_Collvec *)
  153. { // perform locale-specific transform of _Elems [_First1, _Last1)
  154. size_t _Count = _Last2 - _First2;
  155. if (_Count <= (size_t)(_Last1 - _First1))
  156. memcpy(_First1, _First2, _Count * sizeof (_Elem));
  157. return (_Count);
  158. }
  159. template<> inline
  160. size_t __cdecl _LStrxfrm(char *_First1, char *_Last1,
  161. const char *_First2, const char *_Last2,
  162. const _Locinfo::_Collvec *_Vector)
  163. { // perform locale-specific transform of chars [_First1, _Last1)
  164. return (_Strxfrm(_First1, _Last1, _First2, _Last2, _Vector));
  165. }
  166. template<> inline
  167. size_t __cdecl _LStrxfrm(wchar_t *_First1, wchar_t *_Last1,
  168. const wchar_t *_First2, const wchar_t *_Last2,
  169. const _Locinfo::_Collvec *_Vector)
  170. { // perform locale-specific transform of wchar_ts [_First1, _Last1)
  171. return (_Wcsxfrm(_First1, _Last1, _First2, _Last2, _Vector));
  172. }
  173. _STD_END
  174. #pragma warning(pop)
  175. #pragma pack(pop)
  176. #endif /* _XLOCINFO_ */
  177. /*
  178. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  179. * Consult your license regarding permissions and restrictions.
  180. V3.10:0009 */