Implement std::collate.

2001-08-17  Benjamin Kosnik  <bkoz@redhat.com>

	Implement std::collate.
	* config/locale/collate_specializations_gnu.cc: Add here, implement in
	MT-safe way.
	* config/locale/collate_specializations_generic.cc: Add here, but
	in a less sophisticated manner.
	* include/bits/locale_facets.tcc (collate): Add generic definition.
	* include/bits/locale_facets.h (~collate): Mark virtual.
	(collate::_M_compare_helper): New.
	(collate::_M_transform_helper): New.
	* src/locale.cc: Remove unnecessary specializations.
	* src/string-inst.cc: Tweak instantiation of ctors.

	* acinclude.m4 (GLIBCPP_ENABLE_CLOCALE): Do configury for collate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
	* src/Makefile.am (sources): Add collate.cc.
	* src/Makefile.in: Regenerate.

	* testsuite/22_locale/collate_byname.cc: New.
	* testsuite/22_locale/collate.cc: New file.
	* testsuite/22_locale/collate_char_members.cc: New file.
	* testsuite/22_locale/collate_wchar_t_members.cc: New file.

From-SVN: r44996
This commit is contained in:
Benjamin Kosnik 2001-08-18 02:53:13 +00:00 committed by Benjamin Kosnik
parent 5a2586cf8f
commit ea0c0b6e1b
20 changed files with 1585 additions and 972 deletions

View File

@ -1,3 +1,28 @@
2001-08-17 Benjamin Kosnik <bkoz@redhat.com>
Implement std::collate.
* config/locale/collate_specializations_gnu.cc: Add here, implement in
MT-safe way.
* config/locale/collate_specializations_generic.cc: Add here, but
in a less sophisticated manner.
* include/bits/locale_facets.tcc (collate): Add generic definition.
* include/bits/locale_facets.h (~collate): Mark virtual.
(collate::_M_compare_helper): New.
(collate::_M_transform_helper): New.
* src/locale.cc: Remove unnecessary specializations.
* src/string-inst.cc: Tweak instantiation of ctors.
* acinclude.m4 (GLIBCPP_ENABLE_CLOCALE): Do configury for collate.
* aclocal.m4: Regenerate.
* configure: Regenerate.
* src/Makefile.am (sources): Add collate.cc.
* src/Makefile.in: Regenerate.
* testsuite/22_locale/collate_byname.cc: New.
* testsuite/22_locale/collate.cc: New file.
* testsuite/22_locale/collate_char_members.cc: New file.
* testsuite/22_locale/collate_wchar_t_members.cc: New file.
2001-08-16 Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
* configure.target: Set LIMITSH for powerpc-*-*.

View File

@ -1060,6 +1060,7 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
CCODECVT_H=config/locale/codecvt_specializations_generic.h
CMESSAGES_H=config/locale/messages_members_generic.h
CMESSAGES_CC=config/locale/messages_members_generic.cc
CCOLLATE_CC=config/locale/collate_specializations_generic.cc
;;
xgnu)
AC_MSG_RESULT(gnu)
@ -1085,6 +1086,7 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
CCODECVT_H=config/locale/codecvt_specializations_ieee_1003.1-200x.h
CMESSAGES_H=config/locale/messages_members_gnu.h
CMESSAGES_CC=config/locale/messages_members_gnu.cc
CCOLLATE_CC=config/locale/collate_specializations_gnu.cc
;;
xieee_1003.1)
AC_MSG_RESULT(generic)
@ -1097,6 +1099,7 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
CCODECVT_H=config/locale/codecvt_specializations_ieee_1003.1-200x.h
CMESSAGES_H=config/locale/messages_members_ieee_1003.1-200x.h
CMESSAGES_CC=config/locale/messages_members_ieee_1003.1-200x.cc
CCOLLATE_CC=config/locale/collate_specializations_generic.cc
;;
*)
echo "$enable_clocale is an unknown locale package" 1>&2
@ -1114,7 +1117,8 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
AC_SUBST(CCODECVT_H)
AC_SUBST(CMESSAGES_H)
AC_LINK_FILES($CLOCALE_CC, src/c++locale.cc)
AC_LINK_FILES($CMESSAGES_CC, src/messages_members.cc)
AC_LINK_FILES($CMESSAGES_CC, src/messages.cc)
AC_LINK_FILES($CCOLLATE_CC, src/collate.cc)
])

View File

@ -1072,6 +1072,7 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
CCODECVT_H=config/locale/codecvt_specializations_generic.h
CMESSAGES_H=config/locale/messages_members_generic.h
CMESSAGES_CC=config/locale/messages_members_generic.cc
CCOLLATE_CC=config/locale/collate_specializations_generic.cc
;;
xgnu)
AC_MSG_RESULT(gnu)
@ -1097,6 +1098,7 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
CCODECVT_H=config/locale/codecvt_specializations_ieee_1003.1-200x.h
CMESSAGES_H=config/locale/messages_members_gnu.h
CMESSAGES_CC=config/locale/messages_members_gnu.cc
CCOLLATE_CC=config/locale/collate_specializations_gnu.cc
;;
xieee_1003.1)
AC_MSG_RESULT(generic)
@ -1109,6 +1111,7 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
CCODECVT_H=config/locale/codecvt_specializations_ieee_1003.1-200x.h
CMESSAGES_H=config/locale/messages_members_ieee_1003.1-200x.h
CMESSAGES_CC=config/locale/messages_members_ieee_1003.1-200x.cc
CCOLLATE_CC=config/locale/collate_specializations_generic.cc
;;
*)
echo "$enable_clocale is an unknown locale package" 1>&2
@ -1126,7 +1129,8 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
AC_SUBST(CCODECVT_H)
AC_SUBST(CMESSAGES_H)
AC_LINK_FILES($CLOCALE_CC, src/c++locale.cc)
AC_LINK_FILES($CMESSAGES_CC, src/messages_members.cc)
AC_LINK_FILES($CMESSAGES_CC, src/messages.cc)
AC_LINK_FILES($CCOLLATE_CC, src/collate.cc)
])

View File

@ -690,6 +690,9 @@
/* Define if you have the <sys/resource.h> header file. */
#undef HAVE_SYS_RESOURCE_H
/* Define if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

View File

@ -1,3 +1,4 @@
// Wrapper for underlying C-language localization -*- C++ -*-
// Copyright (C) 2001 Free Software Foundation, Inc.
@ -46,7 +47,7 @@ namespace std
// perhaps locale::categories could be made equivalent to LC_*_MASK
// _M_c_locale = __newlocale(1 << LC_ALL, __str.c_str(), NULL);
// _M_c_locale = __newlocale(locale::all, __str.c_str(), NULL);
__cloc = __newlocale(LC_ALL, __s, NULL);
__cloc = __newlocale(1 << LC_ALL, __s, 0);
if (!__cloc)
{
// This named locale is not supported by the underlying OS.

View File

@ -0,0 +1,67 @@
// std::collate implementation details, generic version -*- C++ -*-
// Copyright (C) 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
//
// ISO C++ 14882: 22.2.4.1.2 collate virtual functions
//
// Written by Benjamin Kosnik <bkoz@redhat.com>
#include <locale>
namespace std
{
// These are basically extensions to char_traits, and perhaps should
// be put there instead of here.
template<>
int
collate<char>::_M_compare_helper(const char* __one,
const char* __two) const
{ return strcoll(__one, __two); }
template<>
size_t
collate<char>::_M_transform_helper(char* __to, const char* __from,
size_t __n) const
{ return strxfrm(__to, __from, __n); }
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
int
collate<wchar_t>::_M_compare_helper(const wchar_t* __one,
const wchar_t* __two) const
{ return wcscoll(__one, __two); }
template<>
size_t
collate<wchar_t>::_M_transform_helper(wchar_t* __to, const wchar_t* __from,
size_t __n) const
{ return wcsxfrm(__to, __from, __n); }
#endif
}

View File

@ -0,0 +1,88 @@
// std::collate implementation details, GNU version -*- C++ -*-
// Copyright (C) 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
//
// ISO C++ 14882: 22.2.4.1.2 collate virtual functions
//
// Written by Benjamin Kosnik <bkoz@redhat.com>
#include <locale>
namespace std
{
// These are basically extensions to char_traits, and perhaps should
// be put there instead of here.
template<>
int
collate<char>::_M_compare_helper(const char* __one,
const char* __two) const
{
if (_M_c_locale_collate)
return __strcoll_l(__one, __two, _M_c_locale_collate);
else
return strcoll(__one, __two);
}
template<>
size_t
collate<char>::_M_transform_helper(char* __to, const char* __from,
size_t __n) const
{
if (_M_c_locale_collate)
return __strxfrm_l(__to, __from, __n, _M_c_locale_collate);
else
return strxfrm(__to, __from, __n);
}
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
int
collate<wchar_t>::_M_compare_helper(const wchar_t* __one,
const wchar_t* __two) const
{
if (_M_c_locale_collate)
return __wcscoll_l(__one, __two, _M_c_locale_collate);
else
return wcscoll(__one, __two);
}
template<>
size_t
collate<wchar_t>::_M_transform_helper(wchar_t* __to,
const wchar_t* __from,
size_t __n) const
{
if (_M_c_locale_collate)
return __wcsxfrm_l(__to, __from, __n, _M_c_locale_collate);
else
return wcsxfrm(__to, __from, __n);
}
#endif
}

1678
libstdc++-v3/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -196,7 +196,7 @@ thread_headers = ${thread_builddir}/gthr.h ${thread_builddir}/gthr-single.h
allstamps = stamp-std stamp-bits stamp-c_base stamp-backward stamp-ext stamp-target stamp-thread
# Target inludes for threads
# Target includes for threads
glibcpp_thread_h = @glibcpp_thread_h@
uppercase = [ABCDEFGHIJKLMNOPQRSTUVWXYZ_]
@ -346,7 +346,7 @@ stamp-ext: ${ext_headers}
# This target is special. The timestamp on a directory gets modified
# whenever a file it contains gets modified, and that'll throw off all the
# build dependencies that need this target. On the other hand, someone
# could delete the directory and not the stamp file, faking out the make.
# could delete the directory and not the stamp file, faking out make.
${target_builddir}: stamp-${target_alias}
stamp-${target_alias}:
@if [ ! -d ${target_builddir} ]; then \
@ -354,8 +354,7 @@ stamp-${target_alias}:
echo `date` > stamp-${target_alias} ;\
fi
# c++config would make these be rebuilt all the time.
# we get bizarre symlinks mazes.
# Target includes static.
stamp-target: ${target_headers} ${target_builddir}
@cd ${target_builddir} ;\
if [ ! -f stamp-target ]; then \
@ -368,6 +367,7 @@ stamp-target: ${target_headers} ${target_builddir}
echo `date` > stamp-target; \
fi
# Target includes dynamic.
${target_builddir}/c++config.h: ../config.h \
${glibcpp_srcdir}/include/bits/c++config \
${target_builddir}

View File

@ -520,6 +520,7 @@ namespace std
_S_literals[] = "-+xX0123456789abcdef0123456789ABCDEF";
template<> _Format_cache<char>::_Format_cache();
#ifdef _GLIBCPP_USE_WCHAR_T
template<> _Format_cache<wchar_t>::_Format_cache();
#endif
@ -907,6 +908,7 @@ namespace std
template<>
void
numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
void
@ -944,13 +946,30 @@ namespace std
{
public:
// Types:
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
protected:
// Underlying "C" library locale information saved from
// initialization, needed by collate_byname as well.
__c_locale _M_c_locale_collate;
public:
static locale::id id;
explicit
collate(size_t __refs = 0) : locale::facet(__refs) { }
collate(size_t __refs = 0)
: locale::facet(__refs), _M_c_locale_collate(NULL)
{ }
// Non-standard.
explicit
collate(__c_locale __cloc, size_t __refs = 0)
: locale::facet(__refs)
{
if (__cloc)
_M_c_locale_collate = _S_clone_c_locale(__cloc);
}
int
compare(const _CharT* __lo1, const _CharT* __hi1,
@ -965,8 +984,20 @@ namespace std
hash(const _CharT* __lo, const _CharT* __hi) const
{ return this->do_hash(__lo, __hi); }
// Used to abstract out _CharT bits in virtual member functions, below.
int
_M_compare_helper(const _CharT*, const _CharT*) const;
size_t
_M_transform_helper(_CharT*, const _CharT*, size_t) const;;
protected:
~collate() { } // virtual
virtual
~collate()
{
if (_M_c_locale_collate)
_S_destroy_c_locale(_M_c_locale_collate);
}
virtual int
do_compare(const _CharT* __lo1, const _CharT* __hi1,
@ -982,34 +1013,24 @@ namespace std
template<typename _CharT>
locale::id collate<_CharT>::id;
// Required specializations.
// Specializations.
template<>
int
collate<char>::do_compare(const char* __lo1, const char* __hi1,
const char* __lo2, const char* __hi2) const;
collate<char>::_M_compare_helper(const char*, const char*) const;
template<>
string
collate<char>::do_transform(const char* __lo, const char* __hi) const;
size_t
collate<char>::_M_transform_helper(char*, const char*, size_t) const;
template<>
long
collate<char>::do_hash(const char* __lo, const char* __hi) const;
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
int
collate<wchar_t>::do_compare(const wchar_t* __lo1, const wchar_t* __hi1,
const wchar_t* __lo2,
const wchar_t* __hi2) const;
collate<wchar_t>::_M_compare_helper(const wchar_t*, const wchar_t*) const;
template<>
wstring
collate<wchar_t>::do_transform(const wchar_t* __lo,
const wchar_t* __hi) const;
template<>
long
collate<wchar_t>::do_hash(const wchar_t* __lo, const wchar_t* __hi) const;
size_t
collate<wchar_t>::_M_transform_helper(wchar_t*, const wchar_t*,
size_t) const;
#endif
template<typename _CharT>
@ -1021,19 +1042,15 @@ namespace std
typedef basic_string<_CharT> string_type;
explicit
collate_byname(const char*, size_t __refs = 0);
collate_byname(const char* __s, size_t __refs = 0)
: collate<_CharT>(__refs)
{ _S_create_c_locale(_M_c_locale_collate, __s); }
protected:
virtual
~collate_byname() { }
};
template<>
collate_byname<char>::collate_byname(const char*, size_t __refs);
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
collate_byname<wchar_t>::collate_byname(const char*, size_t __refs);
#endif
class time_base
{
@ -1420,6 +1437,7 @@ namespace std
template<>
void
moneypunct<char>::_M_initialize_moneypunct(__c_locale __cloc);
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
void
@ -1470,10 +1488,10 @@ namespace std
protected:
// Underlying "C" library locale information saved from
// initialization, needed by messages_byname as well.
__c_locale _M_c_locale_messages;
__c_locale _M_c_locale_messages;
#if 1
// Only needed if glibc < 2.3
const char* _M_name_messages;
const char* _M_name_messages;
#endif
public:
@ -1485,6 +1503,7 @@ namespace std
_M_name_messages("C")
{ }
// Non-standard.
explicit
messages(__c_locale __cloc, const char* __name, size_t __refs = 0)
: locale::facet(__refs)

View File

@ -968,7 +968,7 @@ namespace std
__output_float(_OutIter __s, ios_base& __io, _CharT __fill,
const char* __sptr, size_t __slen)
{
// XXX Not currently done: non streambuf_iterator
// XXX Not currently done: non-streambuf_iterator
return __s;
}
@ -1217,10 +1217,75 @@ namespace std
__err |= __io.failbit;
return __out;
}
} // std::
#endif /* _CPP_BITS_LOCFACETS_TCC */
// Generic version does nothing.
template<typename _CharT>
int
collate<_CharT>::
_M_compare_helper(const _CharT*, const _CharT*) const
{ return 0; }
// Generic version does nothing.
template<typename _CharT>
size_t
collate<_CharT>::
_M_transform_helper(_CharT*, const _CharT*, size_t) const
{ return 0; }
template<typename _CharT>
int
collate<_CharT>::
do_compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const
{
const string_type __one(__lo1, __hi1);
const string_type __two(__lo2, __hi2);
return _M_compare_helper(__one.c_str(), __two.c_str());
}
template<typename _CharT>
collate<_CharT>::string_type
collate<_CharT>::
do_transform(const _CharT* __lo, const _CharT* __hi) const
{
string_type __orig(__lo, __hi);
string_type __trans(__orig.size(), char_type());
size_t __res = _M_transform_helper(__trans.begin().base(),
__orig.c_str(), __trans.size());
while (__res >= __trans.size())
{
// Increment size of translated string.
string_type::size_type __newsize = __trans.size() * 2;
__trans.resize(__newsize);
__res = _M_transform_helper(__trans.begin().base(), __orig.c_str(),
__trans.size());
}
return __trans;
}
template<typename _CharT>
long
collate<_CharT>::
do_hash(const _CharT* __lo, const _CharT* __hi) const
{
unsigned long __val = 0;
for (; __lo < __hi; ++__lo)
__val = *__lo + ((__val << 7) |
(__val >> (numeric_limits<unsigned long>::digits - 1)));
return static_cast<long>(__val);
}
} // namespace std
#endif // _CPP_BITS_LOCFACETS_TCC
// Local Variables:
// mode:c++
// End:

View File

@ -21,7 +21,7 @@
## Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
## USA.
## $Id: Makefile.am,v 1.93 2001/08/10 15:47:22 gdr Exp $
## $Id: Makefile.am,v 1.94 2001/08/14 01:24:30 bkoz Exp $
AUTOMAKE_OPTIONS = 1.3 gnits
MAINT_CHARSET = latin1
@ -64,7 +64,8 @@ INCLUDES = \
sources = \
basic_file.cc bitset.cc c++locale.cc cmath.cc codecvt.cc \
complex_io.cc functexcept.cc globals.cc ios.cc limits.cc \
locale.cc locale-inst.cc localename.cc messages_members.cc \
locale.cc locale-inst.cc localename.cc \
messages.cc collate.cc \
misc-inst.cc stdexcept.cc stl-inst.cc string-inst.cc strstream.cc \
valarray-inst.cc wstring-inst.cc

View File

@ -178,7 +178,7 @@ TOPLEVEL_INCLUDES = @TOPLEVEL_INCLUDES@
INCLUDES = -nostdinc++ $(GLIBCPP_INCLUDES) $(LIBSUPCXX_INCLUDES) $(LIBIO_INCLUDES) $(LIBMATH_INCLUDES) $(TOPLEVEL_INCLUDES)
sources = basic_file.cc bitset.cc c++locale.cc cmath.cc codecvt.cc complex_io.cc functexcept.cc globals.cc ios.cc limits.cc locale.cc locale-inst.cc localename.cc messages_members.cc misc-inst.cc stdexcept.cc stl-inst.cc string-inst.cc strstream.cc valarray-inst.cc wstring-inst.cc
sources = basic_file.cc bitset.cc c++locale.cc cmath.cc codecvt.cc complex_io.cc functexcept.cc globals.cc ios.cc limits.cc locale.cc locale-inst.cc localename.cc messages.cc collate.cc misc-inst.cc stdexcept.cc stl-inst.cc string-inst.cc strstream.cc valarray-inst.cc wstring-inst.cc
VPATH = $(top_srcdir):$(top_srcdir)/src
@ -248,9 +248,9 @@ LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libstdc___la_OBJECTS = basic_file.lo bitset.lo c++locale.lo cmath.lo \
codecvt.lo complex_io.lo functexcept.lo globals.lo ios.lo limits.lo \
locale.lo locale-inst.lo localename.lo messages_members.lo misc-inst.lo \
stdexcept.lo stl-inst.lo string-inst.lo strstream.lo valarray-inst.lo \
wstring-inst.lo
locale.lo locale-inst.lo localename.lo messages.lo collate.lo \
misc-inst.lo stdexcept.lo stl-inst.lo string-inst.lo strstream.lo \
valarray-inst.lo wstring-inst.lo
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)

View File

@ -1003,51 +1003,6 @@ namespace std
return __incl_prec;
}
template <>
collate<char>::collate(size_t __refs)
: locale::facet(__refs) { }
template<>
collate<char>::~collate() { }
template<>
int
collate<char>::do_compare(const char* __lo1, const char* __hi1,
const char* __lo2, const char* __hi2) const
{
for (; __lo1 < __hi1 && __lo2 < __hi2; ++__lo1, ++__lo2)
if (*__lo1 != *__lo2)
return (*__lo1 < *__lo2) ? -1 : 1;
if (__lo1 < __hi1)
return 1;
else if (__lo2 < __hi2)
return -1;
else
return 0;
}
template<>
string
collate<char>::
do_transform(const char* __lo, const char* __hi) const
{ return string(__lo, __hi - __lo); }
template<>
long
collate<char>::
do_hash(const char* __lo, const char* __hi) const
{
unsigned long __val = 0xdeadbeef;
for (; __lo < __hi; ++__lo)
__val = *__lo ^ ((__val << 7) &
(__val >> (numeric_limits<unsigned long>::digits - 1)));
return __val;
}
template<>
collate_byname<char>::collate_byname(const char* /*__s*/, size_t __refs)
: collate<char>(__refs) { }
template<>
moneypunct_byname<char, false>::moneypunct_byname(const char* /*__s*/,
size_t __refs)
@ -1214,41 +1169,5 @@ namespace std
ctype_byname<wchar_t>::
ctype_byname(const char* /*__s*/, size_t __refs)
: ctype<wchar_t>(__refs) { }
template<>
collate<wchar_t>::
collate(size_t __refs): locale::facet(__refs) { }
template<>
collate<wchar_t>::
~collate() { }
template<>
int
collate<wchar_t>::
do_compare(const wchar_t* /*__lo1*/, const wchar_t* /*__hi1*/,
const wchar_t* /*__lo2*/, const wchar_t* /*__hi2*/) const
{
return 0; // XXX not done
}
template<>
wstring collate<wchar_t>::
do_transform(const wchar_t* /*__lo*/, const wchar_t* /*__hi*/) const
{
return wstring(); // XXX not done
}
template<>
long collate<wchar_t>::
do_hash(const wchar_t* /*__lo*/, const wchar_t* /*__hi*/) const
{
return 0; // XXX not done
}
template<>
collate_byname<wchar_t>::
collate_byname(const char* /*__s*/, size_t __refs)
: collate<wchar_t> (__refs) { }
#endif // _GLIBCPP_USE_WCHAR_T
} // namespace std

View File

@ -91,11 +91,12 @@ namespace std
// Construct all standard facets and add them to _M_facets.
// XXX Eventually, all should use __clocale ctor like numpunct
_M_init_facet(new std::collate<char>);
// XXX how to deal cleanly, consistently with null ("C") __cloc?
_M_init_facet(new std::collate<char>(__cloc));
_M_init_facet(new std::ctype<char>);
_M_init_facet(new codecvt<char, char, mbstate_t>);
_M_init_facet(new moneypunct<char, false>(__cloc));
_M_init_facet(new moneypunct<char,true >);
_M_init_facet(new moneypunct<char,true>(__cloc));
_M_init_facet(new money_get<char>);
_M_init_facet(new money_put<char>);
_M_init_facet(new numpunct<char>(__cloc));
@ -106,11 +107,11 @@ namespace std
_M_init_facet(new std::messages<char>(__cloc, __str.c_str()));
#ifdef _GLIBCPP_USE_WCHAR_T
_M_init_facet(new std::collate<wchar_t>);
_M_init_facet(new std::collate<wchar_t>(__cloc));
_M_init_facet(new std::ctype<wchar_t>);
_M_init_facet(new codecvt<wchar_t, char, mbstate_t>);
_M_init_facet(new moneypunct<wchar_t, false>(__cloc));
_M_init_facet(new moneypunct<wchar_t,true >);
_M_init_facet(new moneypunct<wchar_t,true>(__cloc));
_M_init_facet(new money_get<wchar_t>);
_M_init_facet(new money_put<wchar_t>);
_M_init_facet(new numpunct<wchar_t>(__cloc));

View File

@ -75,6 +75,9 @@ namespace std
template
S::basic_string(C*, C*, const allocator<C>&);
template
S::basic_string(const C*, const C*, const allocator<C>&);
template
S::basic_string(S::iterator, S::iterator, const allocator<C>&);

View File

@ -0,0 +1,52 @@
// 2001-08-15 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2001 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 22.2.4 The collate category
#include <locale>
void test01()
{
// Check for required base class.
typedef std::messages<char> test_type;
typedef std::locale::facet base_type;
const test_type& obj = std::use_facet<test_type>(std::locale());
const base_type* base = &obj;
// Check for required typedefs
typedef test_type::char_type char_type;
typedef test_type::string_type string_type;
}
// Should be able to instantiate this for other types besides char, wchar_t
class gnu_collate: public std::collate<unsigned char>
{ };
void test02()
{
gnu_collate facet01;
}
int main()
{
test01();
test02();
return 0;
}

View File

@ -0,0 +1,77 @@
// 2001-08-15 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2001 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 22.2.4.2 Template class collate_byname
#include <locale>
#include <testsuite_hooks.h>
// XXX This test is not working for non-glibc locale models.
// { dg-do run { xfail *-*-* } }
void test01()
{
using namespace std;
typedef std::collate<char>::string_type string_type;
bool test = true;
string str;
locale loc_c = locale::classic();
locale loc_byname(locale::classic(), new collate_byname<char>("es_ES"));
str = loc_byname.name();
locale loc_es("es_ES");
str = loc_es.name();
VERIFY( loc_es != loc_byname );
// cache the collate facets
const collate<char>& mssg_byname = use_facet<collate<char> >(loc_byname);
const collate<char>& mssg_de = use_facet<collate<char> >(loc_es);
#if 0
// Check Spanish (es_ES) locale.
catalog cat_de = mssg_de.open("libstdc++", loc_c, dir);
string s01 = mssg_de.get(cat_de, 0, 0, "please");
string s02 = mssg_de.get(cat_de, 0, 0, "thank you");
VERIFY ( s01 == "bitte" );
VERIFY ( s02 == "danke" );
mssg_de.close(cat_de);
// Check byname locale.
catalog cat_byname = mssg_byname.open("libstdc++", loc_c, dir);
string s03 = mssg_byname.get(cat_de, 0, 0, "please");
string s04 = mssg_byname.get(cat_de, 0, 0, "thank you");
VERIFY ( s03 == "bitte" );
VERIFY ( s04 == "danke" );
mssg_byname.close(cat_byname);
VERIFY ( s01 == s03 );
VERIFY ( s02 == s04 );
#endif
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,140 @@
// 2001-08-15 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2001 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 22.2.4.1.1 collate members
#include <locale>
#include <testsuite_hooks.h>
// XXX This may not work for non-glibc locale models.
// { dg-do run { xfail *-*-* } }
void test01()
{
using namespace std;
typedef std::collate<char>::string_type string_type;
bool test = true;
// basic construction
locale loc_c = locale::classic();
locale loc_us("en_US");
locale loc_fr("fr_FR");
locale loc_de("de_DE");
VERIFY( loc_c != loc_de );
VERIFY( loc_us != loc_fr );
VERIFY( loc_us != loc_de );
VERIFY( loc_de != loc_fr );
// cache the collate facets
const collate<char>& coll_c = use_facet<collate<char> >(loc_c);
const collate<char>& coll_us = use_facet<collate<char> >(loc_us);
const collate<char>& coll_fr = use_facet<collate<char> >(loc_fr);
const collate<char>& coll_de = use_facet<collate<char> >(loc_de);
// int compare(const charT*, const charT*, const charT*, const charT*) const
// long hash(const charT*, const charT*) cosnt
// string_type transform(const charT*, const charT*) const
// Check "C" locale.
const char* strlit1 = "monkey picked tikuanyin oolong";
const char* strlit2 = "imperial tea court green oolong";
int i1;
int size1 = strlen(strlit1) - 1;
i1 = coll_c.compare(strlit1, strlit1 + size1, strlit1, strlit1 + 7);
VERIFY ( i1 > 0 );
i1 = coll_c.compare(strlit1, strlit1 + 7, strlit1, strlit1 + size1);
VERIFY ( i1 < 0 );
i1 = coll_c.compare(strlit1, strlit1 + 7, strlit1, strlit1 + 7);
VERIFY ( i1 == 0 );
int i2;
int size2 = strlen(strlit2) - 1;
i2 = coll_c.compare(strlit2, strlit2 + size2, strlit2, strlit2 + 13);
VERIFY ( i2 > 0 );
i2 = coll_c.compare(strlit2, strlit2 + 13, strlit2, strlit2 + size2);
VERIFY ( i2 < 0 );
i2 = coll_c.compare(strlit2, strlit2 + size2, strlit2, strlit2 + size2);
VERIFY ( i2 == 0 );
long l1;
long l2;
l1 = coll_c.hash(strlit1, strlit1 + size1);
l2 = coll_c.hash(strlit1, strlit1 + size1 - 1);
VERIFY ( l1 != l2 );
l1 = coll_c.hash(strlit1, strlit1 + size1);
l2 = coll_c.hash(strlit2, strlit2 + size2);
VERIFY ( l1 != l2 );
string str1 = coll_c.transform(strlit1, strlit1 + size1);
string str2 = coll_c.transform(strlit2, strlit2 + size2);
i1 = coll_c.compare(str1.c_str(), str1.c_str() + size1,
str2.c_str(), str2.c_str() + size2);
i2 = coll_c.compare(strlit1, strlit1 + size1, strlit2, strlit2 + size2);
VERIFY(i1 == i2);
// Check German "de_DE" locale.
const char* strlit3 = "Äuglein Augment"; // "C" == "Augment Äuglein"
const char* strlit4 = "Base baß Baß Bast"; // "C" == "Base baß Baß Bast"
int size3 = strlen(strlit3) - 1;
i1 = coll_de.compare(strlit3, strlit3 + size3, strlit3, strlit3 + 7);
VERIFY ( i1 > 0 );
i1 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + size1);
VERIFY ( i1 < 0 );
i1 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + 7);
VERIFY ( i1 == 0 );
i1 = coll_de.compare(strlit3, strlit3 + 6, strlit3 + 8, strlit3 + 14);
VERIFY ( i1 < 0 );
int size4 = strlen(strlit4) - 1;
i2 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + 13);
VERIFY ( i2 > 0 );
i2 = coll_de.compare(strlit4, strlit4 + 13, strlit4, strlit4 + size4);
VERIFY ( i2 < 0 );
i2 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + size4);
VERIFY ( i2 == 0 );
l1 = coll_de.hash(strlit3, strlit3 + size3);
l2 = coll_de.hash(strlit3, strlit3 + size3 - 1);
VERIFY ( l1 != l2 );
l1 = coll_de.hash(strlit3, strlit3 + size3);
l2 = coll_de.hash(strlit4, strlit4 + size4);
VERIFY ( l1 != l2 );
string str3 = coll_de.transform(strlit3, strlit3 + size3);
string str4 = coll_de.transform(strlit4, strlit4 + size4);
i1 = coll_de.compare(str3.c_str(), str3.c_str() + size3,
str4.c_str(), str4.c_str() + size4);
i2 = coll_de.compare(strlit3, strlit3 + size3, strlit4, strlit4 + size4);
VERIFY(i1 == i2);
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,140 @@
// 2001-08-17 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2001 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 22.2.4.1.1 collate members
#include <locale>
#include <testsuite_hooks.h>
// XXX This may not work for non-glibc locale models.
// { dg-do run { xfail *-*-* } }
void test01()
{
using namespace std;
typedef std::collate<wchar_t>::string_type string_type;
bool test = true;
// basic construction
locale loc_c = locale::classic();
locale loc_us("en_US");
locale loc_fr("fr_FR");
locale loc_de("de_DE");
VERIFY( loc_c != loc_de );
VERIFY( loc_us != loc_fr );
VERIFY( loc_us != loc_de );
VERIFY( loc_de != loc_fr );
// cache the collate facets
const collate<wchar_t>& coll_c = use_facet<collate<wchar_t> >(loc_c);
const collate<wchar_t>& coll_us = use_facet<collate<wchar_t> >(loc_us);
const collate<wchar_t>& coll_fr = use_facet<collate<wchar_t> >(loc_fr);
const collate<wchar_t>& coll_de = use_facet<collate<wchar_t> >(loc_de);
// int compare(const charT*, const charT*, const charT*, const charT*) const
// long hash(const charT*, const charT*) cosnt
// string_type transform(const charT*, const charT*) const
// Check "C" locale.
const wchar_t* strlit1 = L"monkey picked tikuanyin oolong";
const wchar_t* strlit2 = L"imperial tea court green oolong";
int i1;
int size1 = char_traits<wchar_t>::length(strlit1) - 1;
i1 = coll_c.compare(strlit1, strlit1 + size1, strlit1, strlit1 + 7);
VERIFY ( i1 > 0 );
i1 = coll_c.compare(strlit1, strlit1 + 7, strlit1, strlit1 + size1);
VERIFY ( i1 < 0 );
i1 = coll_c.compare(strlit1, strlit1 + 7, strlit1, strlit1 + 7);
VERIFY ( i1 == 0 );
int i2;
int size2 = char_traits<wchar_t>::length(strlit2) - 1;
i2 = coll_c.compare(strlit2, strlit2 + size2, strlit2, strlit2 + 13);
VERIFY ( i2 > 0 );
i2 = coll_c.compare(strlit2, strlit2 + 13, strlit2, strlit2 + size2);
VERIFY ( i2 < 0 );
i2 = coll_c.compare(strlit2, strlit2 + size2, strlit2, strlit2 + size2);
VERIFY ( i2 == 0 );
long l1;
long l2;
l1 = coll_c.hash(strlit1, strlit1 + size1);
l2 = coll_c.hash(strlit1, strlit1 + size1 - 1);
VERIFY ( l1 != l2 );
l1 = coll_c.hash(strlit1, strlit1 + size1);
l2 = coll_c.hash(strlit2, strlit2 + size2);
VERIFY ( l1 != l2 );
wstring str1 = coll_c.transform(strlit1, strlit1 + size1);
wstring str2 = coll_c.transform(strlit2, strlit2 + size2);
i1 = coll_c.compare(str1.c_str(), str1.c_str() + size1,
str2.c_str(), str2.c_str() + size2);
i2 = coll_c.compare(strlit1, strlit1 + size1, strlit2, strlit2 + size2);
VERIFY(i1 == i2);
// Check German "de_DE" locale.
const wchar_t* strlit3 = L"Äuglein Augment"; // "C" == "Augment Äuglein"
const wchar_t* strlit4 = L"Base baß Baß Bast"; // "C" == "Base baß Baß Bast"
int size3 = char_traits<wchar_t>::length(strlit3) - 1;
i1 = coll_de.compare(strlit3, strlit3 + size3, strlit3, strlit3 + 7);
VERIFY ( i1 > 0 );
i1 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + size1);
VERIFY ( i1 < 0 );
i1 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + 7);
VERIFY ( i1 == 0 );
i1 = coll_de.compare(strlit3, strlit3 + 6, strlit3 + 8, strlit3 + 14);
VERIFY ( i1 < 0 );
int size4 = char_traits<wchar_t>::length(strlit4) - 1;
i2 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + 13);
VERIFY ( i2 > 0 );
i2 = coll_de.compare(strlit4, strlit4 + 13, strlit4, strlit4 + size4);
VERIFY ( i2 < 0 );
i2 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + size4);
VERIFY ( i2 == 0 );
l1 = coll_de.hash(strlit3, strlit3 + size3);
l2 = coll_de.hash(strlit3, strlit3 + size3 - 1);
VERIFY ( l1 != l2 );
l1 = coll_de.hash(strlit3, strlit3 + size3);
l2 = coll_de.hash(strlit4, strlit4 + size4);
VERIFY ( l1 != l2 );
wstring str3 = coll_de.transform(strlit3, strlit3 + size3);
wstring str4 = coll_de.transform(strlit4, strlit4 + size4);
i1 = coll_de.compare(str3.c_str(), str3.c_str() + size3,
str4.c_str(), str4.c_str() + size4);
i2 = coll_de.compare(strlit3, strlit3 + size3, strlit4, strlit4 + size4);
VERIFY(i1 == i2);
}
int main()
{
test01();
return 0;
}