From 8445e42a2444577d640709f9645dee6e9a5d48ee Mon Sep 17 00:00:00 2001 From: Steven King Date: Tue, 9 May 2000 01:15:14 +0000 Subject: [PATCH] 2000-0508 Steven King * bits/char_traits.h: use wchar_t utility functions for char_traits methods. * testsuite/21_string/char_traits.cc: New (test02): test char_traits 2000-05-08 Benjamin Kosnik * acinclude.m4 (GLIBCPP_CXXFLAGS): Add bits for solaris2.8. From-SVN: r33783 --- libstdc++-v3/ChangeLog | 9 ++ libstdc++-v3/acinclude.m4 | 12 +-- libstdc++-v3/aclocal.m4 | 12 +-- libstdc++-v3/bits/char_traits.h | 33 ++----- libstdc++-v3/configure | 22 ++--- .../testsuite/21_strings/char_traits.cc | 87 ++++++++++++++++++- 6 files changed, 124 insertions(+), 51 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 661c8ad4579..adb296c5fe2 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ +2000-0508 Steven King + + * bits/char_traits.h: use wchar_t utility functions for + char_traits methods. + * testsuite/21_string/char_traits.cc: New (test02): test + char_traits + 2000-05-08 Benjamin Kosnik + * acinclude.m4 (GLIBCPP_CXXFLAGS): Add bits for solaris2.8. + * bits/fstream.tcc (filebuf::_M_init_filebuf): Don't set _M_buf_size based on macro, instead use _M_buf_size_opt. * bits/std_streambuf.h (basic_streambuf): Add _M_buf_size_opt. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index af4df89db9a..96be15bb61d 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -297,7 +297,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ ctype_default=yes dnl Test for functionality -- gnu-linux - AC_MSG_CHECKING([for gnu-linux ]) + AC_MSG_CHECKING([ for gnu-linux ]) AC_TRY_COMPILE([#include ], [int foo (int a) @@ -313,7 +313,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ dnl Test for functionality -- solaris 2.6 and 2.7 if test $ctype_default = "yes"; then - AC_MSG_CHECKING([for solaris 2.6 or 2.7 ]) + AC_MSG_CHECKING([ for solaris 2.[6,7,8] ]) AC_TRY_COMPILE([#include ], [int foo (int a) @@ -336,7 +336,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ ctype_default=no else ctype_include_dir="config/solaris/solaris2.7" - AC_MSG_RESULT("solaris2.7") + AC_MSG_RESULT("solaris2.[6,7]") ctype_default=no fi fi @@ -344,7 +344,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ dnl Test for functionality -- solaris 2.5.1 if test $ctype_default = "yes"; then - AC_MSG_CHECKING([for solaris 2.5.1 ]) + AC_MSG_CHECKING([ for solaris 2.5.1 ]) AC_TRY_COMPILE([#include ], [int foo (int a) @@ -360,7 +360,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ dnl Test for functionality -- aix if test $ctype_default = "yes"; then - AC_MSG_CHECKING([for aix ]) + AC_MSG_CHECKING([ for aix ]) AC_TRY_COMPILE([#include ], [int foo (int a) @@ -377,7 +377,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ dnl Test for functionality -- newlib if test $ctype_default = "yes"; then - AC_MSG_CHECKING([for newlib ]) + AC_MSG_CHECKING([ for newlib ]) AC_TRY_COMPILE([#include ], [int foo (int a) diff --git a/libstdc++-v3/aclocal.m4 b/libstdc++-v3/aclocal.m4 index ef693aa6ae3..c50d49cc110 100644 --- a/libstdc++-v3/aclocal.m4 +++ b/libstdc++-v3/aclocal.m4 @@ -309,7 +309,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ ctype_default=yes dnl Test for functionality -- gnu-linux - AC_MSG_CHECKING([for gnu-linux ]) + AC_MSG_CHECKING([ for gnu-linux ]) AC_TRY_COMPILE([#include ], [int foo (int a) @@ -325,7 +325,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ dnl Test for functionality -- solaris 2.6 and 2.7 if test $ctype_default = "yes"; then - AC_MSG_CHECKING([for solaris 2.6 or 2.7 ]) + AC_MSG_CHECKING([ for solaris 2.[6,7,8] ]) AC_TRY_COMPILE([#include ], [int foo (int a) @@ -348,7 +348,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ ctype_default=no else ctype_include_dir="config/solaris/solaris2.7" - AC_MSG_RESULT("solaris2.7") + AC_MSG_RESULT("solaris2.[6,7]") ctype_default=no fi fi @@ -356,7 +356,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ dnl Test for functionality -- solaris 2.5.1 if test $ctype_default = "yes"; then - AC_MSG_CHECKING([for solaris 2.5.1 ]) + AC_MSG_CHECKING([ for solaris 2.5.1 ]) AC_TRY_COMPILE([#include ], [int foo (int a) @@ -372,7 +372,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ dnl Test for functionality -- aix if test $ctype_default = "yes"; then - AC_MSG_CHECKING([for aix ]) + AC_MSG_CHECKING([ for aix ]) AC_TRY_COMPILE([#include ], [int foo (int a) @@ -389,7 +389,7 @@ AC_DEFUN(GLIBCPP_CHECK_CTYPE, [ dnl Test for functionality -- newlib if test $ctype_default = "yes"; then - AC_MSG_CHECKING([for newlib ]) + AC_MSG_CHECKING([ for newlib ]) AC_TRY_COMPILE([#include ], [int foo (int a) diff --git a/libstdc++-v3/bits/char_traits.h b/libstdc++-v3/bits/char_traits.h index 50b51b8bd5a..b75b4510c13 100644 --- a/libstdc++-v3/bits/char_traits.h +++ b/libstdc++-v3/bits/char_traits.h @@ -243,48 +243,27 @@ namespace std { static int compare(const char_type* __s1, const char_type* __s2, size_t __n) - { - for (size_t __i = 0; __i < __n; ++__i) - if (!eq(__s1[__i], __s2[__i])) - return lt(__s1[__i], __s2[__i]) ? -1 : 1; - return 0; - } + { return wmemcmp(__s1, __s2, __n); } static size_t length(const char_type* __s) - { - const char_type* __p = __s; - while (*__p) - ++__p; - return (__p - __s); - } + { return wcslen (__s); } static const char_type* find(const char_type* __s, size_t __n, const char_type& __a) - { - for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p) - if (*__p == __a) - return __p; - return 0; - } + { return wmemchr(__s, __a, __n); } static char_type* move(char_type* __s1, const char_type* __s2, int_type __n) - { return static_cast(memmove(__s1, __s2, - __n * sizeof(wchar_t))); } + { return wmemmove(__s1, __s2, __n); } static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) - { return static_cast(memcpy(__s1, __s2, - __n * sizeof(wchar_t))); } + { return wmemcpy(__s1, __s2, __n); } static char_type* assign(char_type* __s, size_t __n, char_type __a) - { - for (char_type* __p = __s; __p < __s + __n; ++__p) - assign(*__p, __a); - return __s; - } + { return wmemset(__s, __a, __n); } static char_type to_char_type(const int_type& __c) { return char_type(__c); } diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 6c438834f45..5123ee4cc77 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -3463,8 +3463,8 @@ if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then ctype_default=yes - echo $ac_n "checking for gnu-linux ""... $ac_c" 1>&6 -echo "configure:3468: checking for gnu-linux " >&5 + echo $ac_n "checking for gnu-linux ""... $ac_c" 1>&6 +echo "configure:3468: checking for gnu-linux " >&5 cat > conftest.$ac_ext <""... $ac_c" 1>&6 -echo "configure:3500: checking for solaris 2.6 or 2.7 " >&5 + echo $ac_n "checking for solaris 2.6,7,8 ""... $ac_c" 1>&6 +echo "configure:3500: checking for solaris 2.6,7,8 " >&5 cat > conftest.$ac_ext <&6 + echo "$ac_t"""solaris2.6,7"" 1>&6 ctype_default=no fi fi fi if test $ctype_default = "yes"; then - echo $ac_n "checking for solaris 2.5.1 ""... $ac_c" 1>&6 -echo "configure:3576: checking for solaris 2.5.1 " >&5 + echo $ac_n "checking for solaris 2.5.1 ""... $ac_c" 1>&6 +echo "configure:3576: checking for solaris 2.5.1 " >&5 cat > conftest.$ac_ext <""... $ac_c" 1>&6 -echo "configure:3608: checking for aix " >&5 + echo $ac_n "checking for aix ""... $ac_c" 1>&6 +echo "configure:3608: checking for aix " >&5 cat > conftest.$ac_ext <""... $ac_c" 1>&6 -echo "configure:3641: checking for newlib " >&5 + echo $ac_n "checking for newlib ""... $ac_c" 1>&6 +echo "configure:3641: checking for newlib " >&5 cat > conftest.$ac_ext < + // [c,d] == _CharT + // [p,q] == const _CharT* + // s == _CharT* + // [n,i,j] == size_t + // f == X::int_type + // pos == X::pos_type + // state == X::state_type + + // void X::assign(wchar_t c, wchar_t d) + // assigns c = d; + wchar_t c1 = L'z'; + wchar_t c2 = L'u'; + test &= c1 != c2; + std::char_traits::assign(c1,c2); + test &= c1 == L'u'; + // char* X::move(char* s, const char* p, size_t n) + // for each i in [0,n) performs X::assign(s[i], p[i]). Copies + // correctly even where p is in [s, s + n), and yields s. + wchar_t array1[] = {L'z', L'u', L'm', L'a', L' ', L'b', L'e', L'a', L'c', L'h', 0}; + const wchar_t str_lit1[] = L"montara and ocean beach"; + int len = sizeof(str_lit1) + sizeof(array1) - 1; // two terminating chars + wchar_t array2[len]; + + test &= str_lit1[0] == 'm'; + c1 = array2[0]; + c2 = str_lit1[0]; + wchar_t c3 = array2[1]; + wchar_t c4 = str_lit1[1]; + std::char_traits::move(array2, str_lit1, 0); + test &= array2[0] == c1; + test &= str_lit1[0] == c2; + std::char_traits::move(array2, str_lit1, 1); + test &= array2[0] == c2; + test &= str_lit1[0] == c2; + test &= array2[1] == c3; + test &= str_lit1[1] == c4; + std::char_traits::move(array2, str_lit1, 2); + test &= array2[0] == c2; + test &= str_lit1[0] == c2; + test &= array2[1] == c4; + test &= str_lit1[1] == c4; + + wchar_t* pc1 = array1 + 1; + c1 = pc1[0]; + c2 = array1[0]; + test &= c1 != c2; + wchar_t* pc2 = std::char_traits::move(array1, pc1, 0); + c3 = pc1[0]; + c4 = array1[0]; + test &= c1 == c3; + test &= c2 == c4; + test &= pc2 == array1; + + c1 = pc1[0]; + c2 = array1[0]; + wchar_t* pc3 = pc1; + pc2 = std::char_traits::move(array1, pc1, 10); + c3 = pc1[0]; + c4 = array1[0]; + test &= c1 != c3; // underlying wchar_t array changed. + test &= c4 != c3; + test &= pc2 == array1; + test &= pc3 == pc1; // but pointers o-tay + c1 = *(str_01.data()); + c2 = array1[0]; + test &= c1 != c2; + #ifdef DEBUG_ASSERT assert(test); #endif return test; } + int main() { test01(); + test02(); } -- 2.30.2