summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libstdc++-v3/ChangeLog13
-rw-r--r--libstdc++-v3/bits/codecvt.h48
-rw-r--r--libstdc++-v3/bits/locale_facets.h90
-rw-r--r--libstdc++-v3/config/gnu-linux/bits/ctype_base.h8
-rw-r--r--libstdc++-v3/config/gnu-linux/bits/ctype_specializations.h1
-rw-r--r--libstdc++-v3/config/gnu-linux/ctype.cc15
-rw-r--r--libstdc++-v3/src/locale.cc64
7 files changed, 153 insertions, 86 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 3debd0e253f..6eec7b59057 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,16 @@
+2000-08-30 Benjamin Kosnik <bkoz@redhat.com>
+
+ * bits/locale_facets.h (ctype<char>): Remove __table_type.
+ Add include for bits/std_cwctype.h, for wctype_t.
+ * src/locale.cc (ctype<wchar_t>): Implement.
+ * config/gnu-linux/bits/ctype_base.h (ctype_base): Remove mask
+ typedef, instead name enum.
+ * config/gnu-linux/bits/ctype_specializations.h: Tweak.
+ * config/gnu-linux/ctype.cc: Tweak.
+ * testsuite/22_locale/ctype.cc: Tweak.
+
+ * bits/codecvt.h (__enc_traits): Mangle names.
+
2000-08-30 Phil Edwards <pme@sources.redhat.com>
* docs/22_locale/codecvt.html: Behind-the-scenes ASCII->HTML
diff --git a/libstdc++-v3/bits/codecvt.h b/libstdc++-v3/bits/codecvt.h
index 27c87b7f270..bc427add940 100644
--- a/libstdc++-v3/bits/codecvt.h
+++ b/libstdc++-v3/bits/codecvt.h
@@ -63,35 +63,35 @@ namespace std
protected:
// Data Members:
// Max size of charset encoding name
- static const int __max_size = 32;
+ static const int _S_max_size = 32;
// Name of internal character set encoding.
- char __intc_enc[__max_size];
+ char _M_intc_enc[_S_max_size];
// Name of external character set encoding.
- char __extc_enc[__max_size];
+ char _M_extc_enc[_S_max_size];
// Conversion descriptor between external encoding to internal encoding.
- __desc_type __in_desc;
+ __desc_type _M_in_desc;
// Conversion descriptor between internal encoding to external encoding.
- __desc_type __out_desc;
+ __desc_type _M_out_desc;
public:
- __enc_traits() : __in_desc(0), __out_desc(0)
+ __enc_traits() : _M_in_desc(0), _M_out_desc(0)
{
// __intc_end = whatever we are using internally, which is
// UCS4 (linux)
// UCS2 == UNICODE (microsoft, java, aix, whatever...)
// XXX Currently don't know how to get this data from target system...
- strcpy(__intc_enc, "UCS4");
+ strcpy(_M_intc_enc, "UCS4");
// __extc_end = external codeset in current locale
- strcpy(__extc_enc, nl_langinfo(CODESET));
+ strcpy(_M_extc_enc, nl_langinfo(CODESET));
}
__enc_traits(const char* __int, const char* __ext)
- : __in_desc(0), __out_desc(0)
+ : _M_in_desc(0), _M_out_desc(0)
{
- strncpy(__intc_enc, __int, __max_size);
- strncpy(__extc_enc, __ext, __max_size);
+ strncpy(_M_intc_enc, __int, _S_max_size);
+ strncpy(_M_extc_enc, __ext, _S_max_size);
}
// 21.1.2 traits typedefs
@@ -101,23 +101,23 @@ namespace std
// CopyConstructible types (20.1.3)
__enc_traits(const __enc_traits& __obj)
{
- strncpy(__intc_enc, __obj.__intc_enc, __max_size);
- strncpy(__extc_enc, __obj.__extc_enc, __max_size);
+ strncpy(_M_intc_enc, __obj._M_intc_enc, _S_max_size);
+ strncpy(_M_extc_enc, __obj._M_extc_enc, _S_max_size);
}
~__enc_traits()
{
- iconv_close(__in_desc);
- iconv_close(__out_desc);
+ iconv_close(_M_in_desc);
+ iconv_close(_M_out_desc);
}
// Initializes
void
_M_init()
{
- __in_desc = iconv_open(__intc_enc, __extc_enc);
- __out_desc = iconv_open(__extc_enc, __intc_enc);
- if (__out_desc == iconv_t(-1) || __in_desc == iconv_t(-1))
+ _M_in_desc = iconv_open(_M_intc_enc, _M_extc_enc);
+ _M_out_desc = iconv_open(_M_extc_enc, _M_intc_enc);
+ if (_M_out_desc == iconv_t(-1) || _M_in_desc == iconv_t(-1))
{
// XXX Extended error checking.
}
@@ -126,25 +126,25 @@ namespace std
bool
_M_good()
{
- return __out_desc && __in_desc
- && __out_desc != iconv_t(-1) && __in_desc != iconv_t(-1);
+ return _M_out_desc && _M_in_desc
+ && _M_out_desc != iconv_t(-1) && _M_in_desc != iconv_t(-1);
}
const __desc_type*
_M_get_in_descriptor()
- { return &__in_desc; }
+ { return &_M_in_desc; }
const __desc_type*
_M_get_out_descriptor()
- { return &__out_desc; }
+ { return &_M_out_desc; }
const char*
_M_get_internal_enc()
- { return __intc_enc; }
+ { return _M_intc_enc; }
const char*
_M_get_external_enc()
- { return __extc_enc; }
+ { return _M_extc_enc; }
};
#endif //_GLIBCPP_USE_WCHAR_T
diff --git a/libstdc++-v3/bits/locale_facets.h b/libstdc++-v3/bits/locale_facets.h
index 94950e4dfe8..db8912400e1 100644
--- a/libstdc++-v3/bits/locale_facets.h
+++ b/libstdc++-v3/bits/locale_facets.h
@@ -39,6 +39,7 @@
#include <bits/std_ctime.h> // For struct tm
#include <bits/std_typeinfo.h> // For bad_cast, which shouldn't be here.
#include <bits/std_ios.h> // For ios_base
+#include <bits/std_cwctype.h> // For wctype_t
namespace std
{
@@ -308,7 +309,7 @@ namespace std
// 22.2.1.3 ctype specializations
- // NB: Can use _Ctype_nois to actually implement the is
+ // NB: Can use _Ctype_nois to actually implement the "is"
// functionality in the non-virtual (thus inline-able) member
// fuctions.
template<>
@@ -316,25 +317,23 @@ namespace std
{
public:
// Types:
- typedef char char_type;
- typedef ctype::mask mask;
- typedef size_t __table_type;
+ typedef char char_type;
+ typedef ctype::mask mask;
private:
// Data Members:
- bool _M_del;
- __to_type const& _M_toupper;
- __to_type const& _M_tolower;
- const mask* const& _M_ctable;
- const mask* _M_table;
+ bool _M_del;
+ __to_type const& _M_toupper;
+ __to_type const& _M_tolower;
+ const mask* const& _M_ctable;
+ const mask* _M_table;
public:
- static locale::id id;
- static const __table_type table_size = 1 +static_cast<unsigned char>(-1);
+ static locale::id id;
+ static const size_t table_size = 1 + static_cast<unsigned char>(-1);
explicit
- ctype(const mask* __table = 0, bool __del = false,
- size_t __refs = 0) throw();
+ ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
inline bool
is(mask __m, char __c) const throw();
@@ -352,11 +351,13 @@ namespace std
virtual
~ctype();
- inline const mask*
+ // XXX
+ const mask*
table() const throw()
{ return _M_table; }
- inline const mask*
+ // XXX
+ const mask*
classic_table() throw()
{ return _M_ctable; }
@@ -397,16 +398,63 @@ namespace std
class ctype<wchar_t> : public _Ctype<wchar_t>
{
public:
- // Types:
- typedef wchar_t char_type;
- typedef ctype::mask mask;
-
- static locale::id id;
+ // Types:
+ typedef wchar_t char_type;
+ typedef ctype::mask mask;
+ typedef wctype_t __wmask_type;
+
+ // Data Members:
+ static locale::id id;
explicit
- ctype(size_t /*__refs*/ = 0) throw();
+ ctype(size_t __refs = 0);
protected:
+ __wmask_type
+ _M_convert_to_wmask(const mask __m) const
+ {
+ __wmask_type __ret;
+ switch (__m)
+ {
+ case space:
+ __ret = wctype("space");
+ break;
+ case print:
+ __ret = wctype("print");
+ break;
+ case cntrl:
+ __ret = wctype("cntrl");
+ break;
+ case upper:
+ __ret = wctype("upper");
+ break;
+ case lower:
+ __ret = wctype("lower");
+ break;
+ case alpha:
+ __ret = wctype("alpha");
+ break;
+ case digit:
+ __ret = wctype("digit");
+ break;
+ case punct:
+ __ret = wctype("punct");
+ break;
+ case xdigit:
+ __ret = wctype("xdigit");
+ break;
+ case alnum:
+ __ret = wctype("alnum");
+ break;
+ case graph:
+ __ret = wctype("graph");
+ break;
+ default:
+ __ret = 0;
+ }
+ return __ret;
+ };
+
virtual
~ctype();
diff --git a/libstdc++-v3/config/gnu-linux/bits/ctype_base.h b/libstdc++-v3/config/gnu-linux/bits/ctype_base.h
index 8d4a65bd040..fbbf376608f 100644
--- a/libstdc++-v3/config/gnu-linux/bits/ctype_base.h
+++ b/libstdc++-v3/config/gnu-linux/bits/ctype_base.h
@@ -35,11 +35,15 @@
struct ctype_base
{
- typedef unsigned short mask;
// Non-standard typedefs.
+ // XXX
+ typedef unsigned short mask;
+ typedef unsigned short __table_type;
typedef const int* __to_type;
- enum
+ // XXX
+ // enum mask
+ enum
{
space = _ISspace,
print = _ISprint,
diff --git a/libstdc++-v3/config/gnu-linux/bits/ctype_specializations.h b/libstdc++-v3/config/gnu-linux/bits/ctype_specializations.h
index 76d4cbcbb79..fdba4e7535e 100644
--- a/libstdc++-v3/config/gnu-linux/bits/ctype_specializations.h
+++ b/libstdc++-v3/config/gnu-linux/bits/ctype_specializations.h
@@ -70,4 +70,3 @@
-
diff --git a/libstdc++-v3/config/gnu-linux/ctype.cc b/libstdc++-v3/config/gnu-linux/ctype.cc
index dc10a63a684..d6a819d68bc 100644
--- a/libstdc++-v3/config/gnu-linux/ctype.cc
+++ b/libstdc++-v3/config/gnu-linux/ctype.cc
@@ -32,9 +32,8 @@
//
// Information as gleaned from /usr/include/ctype.h
-
- ctype<char>::ctype(const mask* __table = 0, bool __del = false,
- size_t __refs = 0) throw()
+
+ ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
: _Ctype_nois<char>(__refs), _M_del(__table != 0 && __del),
_M_toupper(__ctype_toupper), _M_tolower(__ctype_tolower),
_M_ctable(__ctype_b), _M_table(__table == 0 ? _M_ctable: __table)
@@ -42,14 +41,14 @@
char
ctype<char>::do_toupper(char __c) const
- { return _M_toupper[(int) __c]; }
+ { return _M_toupper[static_cast<int>(__c)]; }
const char*
ctype<char>::do_toupper(char* __low, const char* __high) const
{
while (__low < __high)
{
- *__low = _M_toupper[(int) *__low];
+ *__low = _M_toupper[static_cast<int>(*__low)];
++__low;
}
return __high;
@@ -57,16 +56,18 @@
char
ctype<char>::do_tolower(char __c) const
- { return _M_tolower[(int) __c]; }
+ { return _M_tolower[static_cast<int>(__c)]; }
const char*
ctype<char>::do_tolower(char* __low, const char* __high) const
{
while (__low < __high)
{
- *__low = _M_tolower[(int) *__low];
+ *__low = _M_tolower[static_cast<int>(*__low)];
++__low;
}
return __high;
}
+
+
diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc
index 6ceaf12dcc2..8235dd052f8 100644
--- a/libstdc++-v3/src/locale.cc
+++ b/libstdc++-v3/src/locale.cc
@@ -467,7 +467,7 @@ namespace std {
ctype<char>::
~ctype()
- { if (_M_del) delete[] table(); }
+ { if (_M_del) delete[] this->table(); }
char
ctype<char>::
@@ -569,18 +569,18 @@ namespace std {
// NB: These ctype<wchar_t> methods are not configuration-specific,
// unlike the ctype<char> bits.
- ctype<wchar_t>::ctype(size_t /*__refs*/) throw() { }
+ ctype<wchar_t>::ctype(size_t __refs) : _Ctype<wchar_t>(__refs) { }
wchar_t
ctype<wchar_t>::do_toupper(wchar_t __c) const
- { return ::towupper(__c); }
+ { return towupper(__c); }
const wchar_t*
ctype<wchar_t>::do_toupper(wchar_t* __low, const wchar_t* __high) const
{
while (__low < __high)
{
- *__low = ::towupper(*__low);
+ *__low = towupper(*__low);
++__low;
}
return __high;
@@ -588,14 +588,14 @@ namespace std {
wchar_t
ctype<wchar_t>::do_tolower(wchar_t __c) const
- { return ::towlower(__c); }
+ { return towlower(__c); }
const wchar_t*
ctype<wchar_t>::do_tolower(wchar_t* __low, const wchar_t* __high) const
{
while (__low < __high)
{
- *__low = ::towlower(*__low);
+ *__low = towlower(*__low);
++__low;
}
return __high;
@@ -603,68 +603,70 @@ namespace std {
bool
ctype<wchar_t>::
- do_is(mask /*__m*/, char_type /*__c*/) const
- {
- // XXX
- return false;
- }
+ do_is(mask __m, char_type __c) const
+ { return static_cast<bool>(iswctype(_M_convert_to_wmask(__m), __c)); }
const wchar_t*
ctype<wchar_t>::
- do_is(const wchar_t* __low, const wchar_t* /*__high*/, mask* /*__vec*/) const
+ do_is(const wchar_t* __low, const wchar_t* __high, mask* __m) const
{
- // XXX
+ while (__low < __high && !this->is(*__m, *__low))
+ ++__low;
return __low;
}
const wchar_t*
ctype<wchar_t>::
- do_scan_is(mask /*__m*/, const wchar_t* __low, const wchar_t* /*__high*/) const
+ do_scan_is(mask __m, const wchar_t* __low, const wchar_t* __high) const
{
- // XXX
+ while (__low < __high && !this->is(__m, *__low))
+ ++__low;
return __low;
}
const wchar_t*
ctype<wchar_t>::
- do_scan_not(mask /*__m*/, const char_type* __low,
- const char_type* /*__high*/) const
+ do_scan_not(mask __m, const char_type* __low, const char_type* __high) const
{
- // XXX
+ while (__low < __high && this->is(__m, *__low) != 0)
+ ++__low;
return __low;
}
wchar_t
ctype<wchar_t>::
do_widen(char __c) const
- {
- // XXX
- return static_cast<wchar_t>((unsigned char)__c);
- }
+ { return btowc(__c); }
const char*
ctype<wchar_t>::
- do_widen(const char* /*__low*/, const char* __high,
- wchar_t* /*__dest*/) const
+ do_widen(const char* __low, const char* __high, wchar_t* __dest) const
{
- // XXX
+ mbstate_t __state;
+ memset(&__state, 0, sizeof(mbstate_t));
+ mbsrtowcs(__dest, &__low, __high - __low, &__state);
return __high;
}
char
ctype<wchar_t>::
- do_narrow(wchar_t /*__c*/, char __dfault) const
+ do_narrow(wchar_t __wc, char __dfault) const
{
- // XXX
- return __dfault;
+ int __c = wctob(__wc);
+ return (__c == EOF ? __dfault : static_cast<char>(__c));
}
const wchar_t*
ctype<wchar_t>::
- do_narrow(const wchar_t* /*__low*/, const wchar_t* __high,
- char /*__dfault*/, char* /*__dest*/) const
+ do_narrow(const wchar_t* __low, const wchar_t* __high, char __dfault,
+ char* __dest) const
{
- // XXX
+ mbstate_t __state;
+ memset(&__state, 0, sizeof(mbstate_t));
+ size_t __len = __high - __low;
+ size_t __conv = wcsrtombs(__dest, &__low, __len, &__state);
+ if (__conv == __len)
+ *__dest = __dfault;
return __high;
}