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.

92 lines
2.9 KiB

  1. // locale0 -- class locale basic member functions
  2. #include <climits>
  3. #include <locale>
  4. _STD_BEGIN
  5. static locale classic_locale(_Noinit);
  6. locale::_Locimp *locale::_Locimp::_Clocptr = 0;
  7. locale::_Locimp *locale::_Locimp::_Global = 0;
  8. int locale::id::_Id_cnt = 0;
  9. const ctype_base::mask *ctype<char>::_Cltab = 0;
  10. const size_t ctype<char>::table_size = 1 << CHAR_BIT;
  11. const locale& __cdecl locale::classic()
  12. { // get reference to "C" locale
  13. _Init();
  14. _Lockit _Lk;
  15. return (classic_locale);
  16. }
  17. locale __cdecl locale::empty()
  18. { // make empty transparent locale
  19. _Init();
  20. return (locale(new _Locimp(true)));
  21. }
  22. const locale::facet *locale::_Getfacet(size_t _Id,
  23. bool _Xp) const
  24. { // look up a facet in locale object
  25. _Lockit _Lk;
  26. const facet *_F = _Id < _Ptr->_Nfv ? _Ptr->_Fv[_Id] : 0;
  27. return (_F != 0 || !_Xp || !_Ptr->_Xpar ? _F
  28. : _Id < _Locimp::_Global->_Nfv
  29. ? _Locimp::_Global->_Fv[_Id] : 0);
  30. }
  31. bool locale::_Iscloc() const
  32. { // test for underlying dummy C locale object
  33. _Lockit _Lk;
  34. return (_Ptr == _Locimp::_Clocptr || _Ptr->_Xpar
  35. && _Locimp::_Global == _Locimp::_Clocptr);
  36. }
  37. bool locale::operator==(const locale& _X) const
  38. { // compare locales for equality
  39. return (_Ptr == _X._Ptr || name().compare("*") != 0
  40. && name().compare(_X.name()) == 0);
  41. }
  42. locale::_Locimp *__cdecl locale::_Init()
  43. { // setup _Global and "C" locales
  44. _Lockit _Lk;
  45. if (_Locimp::_Global == 0)
  46. { // create new locales
  47. _Locimp::_Global = new _Locimp;
  48. atexit(&_Tidy);
  49. _Locimp::_Global->_Cat = all;
  50. _Locimp::_Global->_Name = "C";
  51. _Locimp::_Clocptr = _Locimp::_Global;
  52. _Locimp::_Clocptr->_Incref();
  53. new (&classic_locale) locale(_Locimp::_Clocptr);
  54. }
  55. return (_Locimp::_Global);
  56. }
  57. void __cdecl locale::_Tidy()
  58. { // discard _Global locale
  59. _Lockit _Lk;
  60. if (_Locimp::_Global != 0)
  61. delete _Locimp::_Global->_Decref();
  62. }
  63. locale::_Locimp::_Locimp(bool _Xp)
  64. : locale::facet(1), _Fv(0), _Nfv(0),
  65. _Cat(none), _Xpar(_Xp), _Name("*")
  66. { // construct an empty _Locimp
  67. }
  68. locale::_Locimp::~_Locimp()
  69. { // destruct a _Locimp
  70. _Lockit _Lk;
  71. for (size_t _N = _Nfv; 0 < _N; )
  72. if (_Fv[--_N] != 0)
  73. delete _Fv[_N]->_Decref();
  74. free(_Fv);
  75. }
  76. _STD_END
  77. /*
  78. * Copyright (c) 1996 by P.J. Plauger. ALL RIGHTS RESERVED.
  79. * Consult your license regarding permissions and restrictions.
  80. */