// locale standard header #pragma once #ifndef _LOCALE_ #define _LOCALE_ #include #include #include #include #include #pragma pack(push,8) #pragma warning(push,3) _STD_BEGIN // TEMPLATE CLASS collate template class collate : public locale::facet { // facet for ordering sequences of elements public: typedef _Elem char_type; typedef basic_string<_Elem, char_traits<_Elem>, allocator<_Elem> > string_type; int compare(const _Elem *_First1, const _Elem *_Last1, const _Elem *_First2, const _Elem *_Last2) const { // compare [_First1, _Last1) to [_First2, _Last2) return (do_compare(_First1, _Last1, _First2, _Last2)); } string_type transform(const _Elem *_First, const _Elem *_Last) const { // transform [_First, _Last) to key string return (do_transform(_First, _Last)); } long hash(const _Elem *_First, const _Elem *_Last) const { // compute hash code for [_First, _Last) return (do_hash(_First, _Last)); } static locale::id id; // unique facet id explicit collate(size_t _Refs = 0) : locale::facet(_Refs) { // construct from current locale _Init(_Locinfo()); } collate(const _Locinfo& _Lobj, size_t _Refs = 0) : locale::facet(_Refs) { // construct from specified locale _Init(_Lobj); } static size_t __cdecl _Getcat(const locale::facet **_Ppf = 0) { // return locale category mask and construct standard facet if (_Ppf != 0 && *_Ppf == 0) *_Ppf = _NEW_CRT collate<_Elem>; return (_X_COLLATE); } _PROTECTED: ~collate() { // destroy the object } protected: void _Init(const _Locinfo& _Lobj) { // initialize from _Lobj _Coll = _Lobj._Getcoll(); } virtual int do_compare(const _Elem *_First1, const _Elem *_Last1, const _Elem *_First2, const _Elem *_Last2) const { // compare [_First1, _Last1) to [_First2, _Last2) return (_LStrcoll(_First1, _Last1, _First2, _Last2, &_Coll)); } virtual string_type do_transform(const _Elem *_First, const _Elem *_Last) const { // transform [_First, _Last) to key string size_t _Count; string_type _Str; for (_Count = _Last - _First; ; ) { // grow string if locale-specific strxfrm fails _Str.resize(_Count); if ((_Count = _LStrxfrm(&*_Str.begin(), &*_Str.end(), _First, _Last, &_Coll)) <= _Str.size()) break; } _Str.resize(_Count); return (_Str); } virtual long do_hash(const _Elem *_First, const _Elem *_Last) const { // compute hash code for [_First, _Last) unsigned long _Val = 0; for (; _First != _Last; ++_First) _Val = (_Val << 8 | _Val >> 24) + *_First; return ((long)_Val); } private: _Locinfo::_Collvec _Coll; // used by _LStrcoll and _XStrxfrm }; // STATIC collate::id OBJECT template locale::id collate<_Elem>::id; #ifdef _DLL_CPPLIB #ifdef __FORCE_INSTANCE template class _CRTIMP2 collate; template class _CRTIMP2 collate; #ifdef _CRTBLD_NATIVE_WCHAR_T template class _CRTIMP2 collate; #endif #endif // __FORCE_INSTANCE #endif // _DLL_CPPLIB // TEMPLATE CLASS collate_byname template class collate_byname : public collate<_Elem> { // collate for named locale public: explicit collate_byname(const char *_Locname, size_t _Refs = 0) : collate<_Elem>(_Locinfo(_Locname), _Refs) { // construct for named locale } _PROTECTED: virtual ~collate_byname() { // destroy the object } }; // locale SUPPORT TEMPLATES #define _HAS(loc, fac) has_facet(loc) template inline bool has_facet(const locale& _Loc) _THROW0() { // test if facet is in locale _Lockit _Lock(_LOCK_LOCALE); // the thread lock, make get atomic size_t _Id = _Facet::id; return (_Loc._Getfacet(_Id) != 0 || _Facet::_Getcat() != (size_t)(-1)); } template inline _DEPRECATED bool has_facet(const locale& _Loc, const _Facet *) _THROW0() { // test if facet is in locale -- retained, two arg version return (has_facet<_Facet>(_Loc)); } // ctype TEMPLATE FUNCTIONS template inline bool (isalnum)(_Elem _Ch, const locale& _Loc) { // test if character is alphanumeric, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::alnum, _Ch)); } template inline bool (isalpha)(_Elem _Ch, const locale& _Loc) { // test if character is alphabetic, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::alpha, _Ch)); } template inline bool (iscntrl)(_Elem _Ch, const locale& _Loc) { // test if character is control, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::cntrl, _Ch)); } template inline bool (isdigit)(_Elem _Ch, const locale& _Loc) { // test if character is digit, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::digit, _Ch)); } template inline bool (isgraph)(_Elem _Ch, const locale& _Loc) { // test if character is graphic, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::graph, _Ch)); } template inline bool (islower)(_Elem _Ch, const locale& _Loc) { // test if character is lower case, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::lower, _Ch)); } template inline bool (isprint)(_Elem _Ch, const locale& _Loc) { // test if character is printing, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::print, _Ch)); } template inline bool (ispunct)(_Elem _Ch, const locale& _Loc) { // test if character is punctuation, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::punct, _Ch)); } template inline bool (isspace)(_Elem _Ch, const locale& _Loc) { // test if character is whitespace, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::space, _Ch)); } template inline bool (isupper)(_Elem _Ch, const locale& _Loc) { // test if character is upper case, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::upper, _Ch)); } template inline bool (isxdigit)(_Elem _Ch, const locale& _Loc) { // test if character is hexadecimal digit, locale specific return (_USE(_Loc, ctype<_Elem>).is(ctype_base::xdigit, _Ch)); } template inline _Elem (tolower)(_Elem _Ch, const locale& _Loc) { // convert character to lower case, locale specific return (_USE(_Loc, ctype<_Elem>).tolower(_Ch)); } template inline _Elem (toupper)(_Elem _Ch, const locale& _Loc) { // convert character to upper case, locale specific return (_USE(_Loc, ctype<_Elem>).toupper(_Ch)); } _STD_END #pragma warning(pop) #pragma pack(pop) #endif /* _LOCALE_ */ /* * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED. * Consult your license regarding permissions and restrictions. V3.10:0009 */