This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[RFC] wstring on platforms without C99 wchar_t support
- From: Pétur Runólfsson <peturr02 at ru dot is>
- To: <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 15 Jul 2003 19:07:32 -0000
- Subject: [RFC] wstring on platforms without C99 wchar_t support
Hi,
It seems that at least twice a week someone notes that wstring is
missing on a lot of platforms.
The following patch adds wstring support to platforms on
which _GLIBCXX_USE_WCHAR_T is not defined, by providing inline
implementations of those char_traits<wchar_t> members that are
used by basic_string.
This passes all wchar_t tests in 21_strings, except for those
in inserters_extractors and c_strings/wchar_t/1.cc.
Tested on i686-pc-cygwin (Windows XP)
Am I missing something obvious? Should the typedefs off_type,
pos_type and state_type be provided? What about int_type? Should
the functions that take int_type parameters be declared? How do
I make dejagnu run the wchar_t tests under 21_strings but not
under 22_locale or 27_io?
Regards,
Petur
Index: include/bits/char_traits.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/char_traits.h,v
retrieving revision 1.19
diff -c -3 -p -r1.19 char_traits.h
*** include/bits/char_traits.h 15 Jul 2003 17:30:10 -0000 1.19
--- include/bits/char_traits.h 15 Jul 2003 18:41:28 -0000
*************** namespace std
*** 180,195 ****
};
- #ifdef _GLIBCXX_USE_WCHAR_T
/// 21.1.3.2 char_traits specializations
template<>
struct char_traits<wchar_t>
{
typedef wchar_t char_type;
typedef wint_t int_type;
typedef streamoff off_type;
typedef wstreampos pos_type;
typedef mbstate_t state_type;
static void
assign(char_type& __c1, const char_type& __c2)
--- 180,196 ----
};
/// 21.1.3.2 char_traits specializations
template<>
struct char_traits<wchar_t>
{
typedef wchar_t char_type;
+ #ifdef _GLIBCXX_USE_WCHAR_T
typedef wint_t int_type;
typedef streamoff off_type;
typedef wstreampos pos_type;
typedef mbstate_t state_type;
+ #endif //_GLIBCXX_USE_WCHAR_T
static void
assign(char_type& __c1, const char_type& __c2)
*************** namespace std
*** 205,232 ****
static int
compare(const char_type* __s1, const char_type* __s2, size_t __n)
{ return wmemcmp(__s1, __s2, __n); }
static size_t
length(const char_type* __s)
{ return wcslen(__s); }
static const char_type*
find(const char_type* __s, size_t __n, const char_type& __a)
{ return wmemchr(__s, __a, __n); }
static char_type*
move(char_type* __s1, const char_type* __s2, size_t __n)
{ return wmemmove(__s1, __s2, __n); }
static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n)
{ return wmemcpy(__s1, __s2, __n); }
static char_type*
assign(char_type* __s, size_t __n, char_type __a)
{ return wmemset(__s, __a, __n); }
static char_type
to_char_type(const int_type& __c) { return char_type(__c); }
--- 206,294 ----
static int
compare(const char_type* __s1, const char_type* __s2, size_t __n)
+ #ifdef _GLIBCXX_USE_WCHAR_T
{ return wmemcmp(__s1, __s2, __n); }
+ #else
+ {
+ while (__n--)
+ {
+ if (*__s1 < *__s2)
+ return -1;
+ else if (*__s1 > *__s2)
+ return +1;
+
+ ++__s1;
+ ++__s2;
+ }
+ return 0;
+ }
+ #endif //_GLIBCXX_USE_WCHAR_T
static size_t
length(const char_type* __s)
+ #ifdef _GLIBCXX_USE_WCHAR_T
{ return wcslen(__s); }
+ #else
+ {
+ size_t __ret = 0;
+ while (*__s++)
+ ++__ret;
+ return __ret;
+ }
+ #endif //_GLIBCXX_USE_WCHAR_T
static const char_type*
find(const char_type* __s, size_t __n, const char_type& __a)
+ #ifdef _GLIBCXX_USE_WCHAR_T
{ return wmemchr(__s, __a, __n); }
+ #else
+ {
+ while (__n--)
+ {
+ if (*__s == __a)
+ return __s;
+ ++__s;
+ }
+ return 0;
+ }
+ #endif //_GLIBCXX_USE_WCHAR_T
static char_type*
move(char_type* __s1, const char_type* __s2, size_t __n)
+ #ifdef _GLIBCXX_USE_WCHAR_T
{ return wmemmove(__s1, __s2, __n); }
+ #else
+ {
+ memmove(__s1, __s2, __n * sizeof(wchar_t));
+ return __s1;
+ }
+ #endif //_GLIBCXX_USE_WCHAR_T
static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n)
+ #ifdef _GLIBCXX_USE_WCHAR_T
{ return wmemcpy(__s1, __s2, __n); }
+ #else
+ {
+ memcpy(__s1, __s2, __n * sizeof(wchar_t));
+ return __s1;
+ }
+ #endif //_GLIBCXX_USE_WCHAR_T
static char_type*
assign(char_type* __s, size_t __n, char_type __a)
+ #ifdef _GLIBCXX_USE_WCHAR_T
{ return wmemset(__s, __a, __n); }
+ #else
+ {
+ char_type* __ret = __s;
+ while (__n--)
+ *__s++ = __a;
+ return __ret;
+ }
+ #endif //_GLIBCXX_USE_WCHAR_T
+ #ifdef _GLIBCXX_USE_WCHAR_T
static char_type
to_char_type(const int_type& __c) { return char_type(__c); }
*************** namespace std
*** 243,250 ****
static int_type
not_eof(const int_type& __c)
{ return eq_int_type(__c, eof()) ? 0 : __c; }
};
- #endif //_GLIBCXX_USE_WCHAR_T
template<typename _CharT, typename _Traits>
struct _Char_traits_match
--- 305,312 ----
static int_type
not_eof(const int_type& __c)
{ return eq_int_type(__c, eof()) ? 0 : __c; }
+ #endif //_GLIBCXX_USE_WCHAR_T
};
template<typename _CharT, typename _Traits>
struct _Char_traits_match
Index: include/bits/stringfwd.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/stringfwd.h,v
retrieving revision 1.9
diff -c -3 -p -r1.9 stringfwd.h
*** include/bits/stringfwd.h 5 Jul 2003 04:05:36 -0000 1.9
--- include/bits/stringfwd.h 15 Jul 2003 18:41:28 -0000
*************** namespace std
*** 59,69 ****
typedef basic_string<char> string;
- #ifdef _GLIBCXX_USE_WCHAR_T
template<> struct char_traits<wchar_t>;
typedef basic_string<wchar_t> wstring;
- #endif
} // namespace std
#endif // _STRINGFWD_H
--- 59,67 ----