// locale standard header
#ifndef _LOCALE_
#define _LOCALE_

#pragma info(none)
#ifndef __CHKHDR__
#  pragma report(level, E)
#endif
#pragma info(restore)

#if __IBMCPP__ < 400
#error This file to be used only with IBM VisualAge C++ v4 and later compilers.
#endif /* __IBMCPP__ */

#pragma namemangling(ansi)

   /********************************************************************/
   /*  <locale> header file                                            */
   /*                                                                  */
   /*  VisualAge C++, Version 4.0                                      */
   /*    Licensed Material - Property of IBM                           */
   /*                                                                  */
   /*  5801-AAR and Other Materials                                    */
   /*                                                                  */
   /*  (c) Copyright IBM Corp 1991, 1998. All rights reserved.         */
   /*                                                                  */
   /*                                                                  */
   /*  Licensed Materials.                                             */
   /*                                                                  */
   /*  Dinkum C++ Library                                              */
   /*  Copyright (c) 1998.  Licensed to IBM Corp. and its suppliers.   */
   /*                                                                  */
   /********************************************************************/

#include <string>
#include <xlocmes>
#include <xlocmon>
#include <xlocnum>
#include <xloctime>
_STD_BEGIN
		// TEMPLATE CLASS collate
template<class _E>
	class collate : public locale::facet {
public:
	typedef _E char_type;
	typedef basic_string<_E, char_traits<_E>,
		allocator<_E> > string_type;
	int compare(const _E *_F1, const _E *_L1,
		const _E *_F2, const _E *_L2) const
		{return (do_compare(_F1, _L1, _F2, _L2)); }
	string_type transform(const _E *_F, const _E *_L) const
		{return (do_transform(_F, _L)); }
	long hash(const _E *_F, const _E *_L) const
		{return (do_hash(_F, _L)); }
	static locale::id id;
	explicit collate(size_t _R = 0)
		: locale::facet(_R) {_Init(_Locinfo()); }
	collate(const _Locinfo& _Lobj, size_t _R = 0)
		: locale::facet(_R) {_Init(_Lobj); }
	static size_t _Getcat(const locale::facet **_Ppf = 0)
		{if (_Ppf != 0 && *_Ppf == 0)
			*_Ppf = new collate<_E>;
		return (_X_COLLATE); }
_PROTECTED:
	~collate()
		{}
protected:
	void _Init(const _Locinfo& _Lobj)
		{_Coll = _Lobj._Getcoll(); }
	virtual int do_compare(const _E *_F1, const _E *_L1,
		const _E *_F2, const _E *_L2) const
		{return (_LStrcoll(_F1, _L1, _F2, _L2, &_Coll)); }
	virtual string_type do_transform(const _E *_F,
		const _E *_L) const
		{size_t _I, _N;
		string_type _Str;
		for (_N = _L - _F; ; )
			{_Str.append(_N, '\0');
			if ((_I = _LStrxfrm(&*_Str.begin(), &*_Str.end(),
					_F, _L, &_Coll)) <= _Str.size())
				break;
			_N = _Str.size() < _I ? _I - _Str.size() : 1; }
		_Str.resize(_I);
		return (_Str); }
	virtual long do_hash(const _E *_F, const _E *_L) const
		{unsigned long _V = 0;
		for (; _F != _L; ++_F)
			_V = (_V << 8 | _V >> 24) + *_F;
		return ((long)_V); }
private:
	_Locinfo::_Collvec _Coll;
	};
template<class _E>
	locale::id collate<_E>::id;
		// TEMPLATE CLASS collate_byname
template<class _E>
	class collate_byname : public collate<_E> {
public:
	explicit collate_byname(const char *_S, size_t _R = 0)
		: collate<_E>(_Locinfo(_S), _R) {}
_PROTECTED:
	virtual ~collate_byname()
		{}
	};
		// locale SUPPORT TEMPLATES
 #define _HAS(loc, fac)	has_facet<fac>(loc)
template<class _F> inline
	bool has_facet(const locale& _L) _THROW0()
	{size_t _Id = _F::id;
	return (_L._Getfacet(_Id) != 0
		|| _F::_Getcat() != (size_t)(-1)); }
template<class _E, class _Tr, class _A> inline
	bool locale::operator()(const basic_string<_E, _Tr, _A>& _X,
		const basic_string<_E, _Tr, _A>& _Y) const
	{const typename std::collate<_E>& _Fac =
           _USE(*this, typename std::collate<_E>);
	return (_Fac.compare(_X.c_str(), _X.c_str() + _X.size(),
		_Y.c_str(), _Y.c_str() + _Y.size()) < 0); }
template<class _F> inline
	locale locale::combine(const locale& _X) const
	{_F *_Fac;
	_TRY_BEGIN
		_Fac = (_F *)&_USE(_X, _F);
	_CATCH_ALL
		_THROW(runtime_error, "");
	_CATCH_END
	_Locimp *_P = new _Locimp(_Ptr);
	_P->_Addfac(_Fac, _F::id);
	if (_F::_Getcat() != (size_t)(-1))
		_P->_Cat = 0, _P->_Name = "*";
	return (locale(_P)); }
		// ctype TEMPLATE FUNCTIONS
template<class _E> inline
	bool (isalnum)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::alnum, _C)); }
template<class _E> inline
	bool (isalpha)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::alpha, _C)); }
template<class _E> inline
	bool (iscntrl)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::cntrl, _C)); }
template<class _E> inline
	bool (isdigit)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::digit, _C)); }
template<class _E> inline
	bool (isgraph)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::graph, _C)); }
template<class _E> inline
	bool (islower)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::lower, _C)); }
template<class _E> inline
	bool (isprint)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::print, _C)); }
template<class _E> inline
	bool (ispunct)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::punct, _C)); }
template<class _E> inline
	bool (isspace)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::space, _C)); }
template<class _E> inline
	bool (isupper)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::upper, _C)); }
template<class _E> inline
	bool (isxdigit)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).is(ctype_base::xdigit, _C)); }
template<class _E> inline
	_E (tolower)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).tolower(_C)); }
template<class _E> inline
	_E (toupper)(_E _C, const locale& _L)
	{return (_USE(_L, ctype<_E>).toupper(_C)); }
_STD_END

#pragma namemangling()

#pragma info(none)
#ifndef __CHKHDR__
#  pragma report(pop)
#endif
#pragma info(restore)

#endif /* _LOCALE_ */

/*
 * Copyright (c) 1995 by P.J. Plauger.  ALL RIGHTS RESERVED. 
 * Consult your license regarding permissions and restrictions.
V2.2:0081 */
