This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Lot of work on locale_facets.cc & co.


Hi,

tested x86-linux, committed.

wheee... (I like Jeff's wheee-s so much! ;)

Paolo.

////////////
2003-10-27  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/12750
	* include/bits/locale_facets.tcc
	(time_get::_M_extract_via_format): Deal with code 'e'.
	* testsuite/22_locale/time_get/get_date/char/12750.cc: New.
	* testsuite/22_locale/time_get/get_date/wchar_t/12750.cc: Ditto.

	* include/bits/locale_facets.tcc
	(time_get::_M_extract_via_format): Tweak to absolutely avoid
	dereferencing end iterators.

	* include/bits/locale_facets.h (__verify_grouping):
	Const-ify second parameter.
	* include/bits/locale_facets.tcc (__verify_grouping): Ditto.
	* src/locale-inst.cc (__verify_grouping): Ditto.

2003-10-27  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (num_get::_M_extract_float):
	Various things: 1- Avoid absolutely end iterator dereferences;
	2- Improve performance-wise the code skipping leading zeros;
	3- Fix two bugs wrt early bail out in case of parsing errors
	(see testcases); 4- General clean up.
	(num_get::_M_extract_int): Likewise, except 3-. Additionally,
	use __builtin_expect to favor base 10 inputs.
	* testsuite/22_locale/num_get/get/char/7.cc: New.
	* testsuite/22_locale/num_get/get/wchar_t/7.cc: Ditto.
diff -prN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
*** libstdc++-v3-orig/include/bits/locale_facets.tcc	Sat Oct 25 11:16:39 2003
--- libstdc++-v3/include/bits/locale_facets.tcc	Sun Oct 26 09:11:15 2003
*************** namespace std
*** 144,194 ****
        const _CharT* __lit = __lc->_M_atoms_in;
  
        // First check for sign.
!       int __pos = 0;
!       char_type  __c = *__beg;
!       const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]);
!       if ((__plus || __traits_type::eq(__c, __lit[_S_iminus])) 
! 	  && __beg != __end)
! 	{
! 	  __xtrc += __plus ? _S_atoms_in[_S_iplus] : _S_atoms_in[_S_iminus];
! 	  ++__pos;
! 	  __c = *(++__beg);
! 	}
! 
!       // Next, strip leading zeros.
!       bool __found_zero = false;
!       while (__traits_type::eq(__c, __lit[_S_izero]) && __beg != __end)
  	{
! 	  __c = *(++__beg);
! 	  __found_zero = true;
  	}
!       if (__found_zero)
  	{
  	  __xtrc += _S_atoms_in[_S_izero];
! 	  ++__pos;
  	}
  
        // Only need acceptable digits for floating point numbers.
        bool __found_dec = false;
        bool __found_sci = false;
        string __found_grouping;
-       const size_t __len = _S_iE - _S_izero + 1;
        int __sep_pos = 0;
        bool __e;
        while (__beg != __end)
          {
  	  // Only look in digits.
            const char_type* __p = __traits_type::find(__lit + _S_izero, 10, 
  						     __c);
! 
!           // NB: strchr returns true for __c == 0x0
            if (__p && !__traits_type::eq(__c, char_type()))
  	    {
  	      // Try first for acceptable digit; record it if found.
- 	      ++__pos;
  	      __xtrc += _S_atoms_in[__p - __lit];
  	      ++__sep_pos;
! 	      __c = *(++__beg);
  	    }
            else if (__traits_type::eq(__c, __lc->_M_thousands_sep) 
  		   && __lc->_M_use_grouping && !__found_dec)
--- 144,193 ----
        const _CharT* __lit = __lc->_M_atoms_in;
  
        // First check for sign.
!       if (__beg != __end)
  	{
! 	  const char_type __c = *__beg;
! 	  const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]);
! 	  if (__plus || __traits_type::eq(__c, __lit[_S_iminus]))
! 	    {
! 	      __xtrc += __plus ? _S_atoms_in[_S_iplus]
! 		               : _S_atoms_in[_S_iminus];
! 	      ++__beg;
! 	    }
  	}
! 	  
!       // Next, look for a zero...
!       bool __found_mantissa = false;
!       if (__beg != __end && __traits_type::eq(*__beg, __lit[_S_izero]))
  	{
  	  __xtrc += _S_atoms_in[_S_izero];
! 	  __found_mantissa = true;
! 	  ++__beg;
! 	  // ... and skip the additional ones.
! 	  for (; __beg != __end
! 		 && __traits_type::eq(*__beg, __lit[_S_izero]); ++__beg);
  	}
  
        // Only need acceptable digits for floating point numbers.
        bool __found_dec = false;
        bool __found_sci = false;
        string __found_grouping;
        int __sep_pos = 0;
        bool __e;
        while (__beg != __end)
          {
  	  // Only look in digits.
+ 	  const char_type __c = *__beg;
            const char_type* __p = __traits_type::find(__lit + _S_izero, 10, 
  						     __c);
!           // NB: strchr returns true for *__beg == 0x0
            if (__p && !__traits_type::eq(__c, char_type()))
  	    {
  	      // Try first for acceptable digit; record it if found.
  	      __xtrc += _S_atoms_in[__p - __lit];
+ 	      __found_mantissa = true;
  	      ++__sep_pos;
! 	      ++__beg;
  	    }
            else if (__traits_type::eq(__c, __lc->_M_thousands_sep) 
  		   && __lc->_M_use_grouping && !__found_dec)
*************** namespace std
*** 199,205 ****
                  {
                    __found_grouping += static_cast<char>(__sep_pos);
                    __sep_pos = 0;
! 		  __c = *(++__beg);
                  }
                else
  		{
--- 198,204 ----
                  {
                    __found_grouping += static_cast<char>(__sep_pos);
                    __sep_pos = 0;
! 		  ++__beg;
                  }
                else
  		{
*************** namespace std
*** 215,242 ****
  	      // must be adjusted only if __dec comes after some __sep.
  	      if (__found_grouping.size())
  		__found_grouping += static_cast<char>(__sep_pos);
- 	      ++__pos;
  	      __xtrc += '.';
- 	      __c = *(++__beg);
  	      __found_dec = true;
  	    }
  	  else if ((__e = __traits_type::eq(__c, __lit[_S_ie]) 
  		    || __traits_type::eq(__c, __lit[_S_iE])) 
! 		   && !__found_sci && __pos)
  	    {
  	      // Scientific notation.
- 	      ++__pos;
  	      __xtrc += __e ? _S_atoms_in[_S_ie] : _S_atoms_in[_S_iE];
! 	      __c = *(++__beg);
! 
  	      // Remove optional plus or minus sign, if they exist.
! 	      const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]);
! 	      if (__plus || __traits_type::eq(__c, __lit[_S_iminus]))
  		{
! 		  ++__pos;
! 		  __xtrc += __plus ? _S_atoms_in[_S_iplus] 
! 		                   : _S_atoms_in[_S_iminus];
! 		  __c = *(++__beg);
  		}
  	      __found_sci = true;
  	    }
--- 214,241 ----
  	      // must be adjusted only if __dec comes after some __sep.
  	      if (__found_grouping.size())
  		__found_grouping += static_cast<char>(__sep_pos);
  	      __xtrc += '.';
  	      __found_dec = true;
+ 	      ++__beg;
  	    }
  	  else if ((__e = __traits_type::eq(__c, __lit[_S_ie]) 
  		    || __traits_type::eq(__c, __lit[_S_iE])) 
! 		   && __found_mantissa && !__found_sci)
  	    {
  	      // Scientific notation.
  	      __xtrc += __e ? _S_atoms_in[_S_ie] : _S_atoms_in[_S_iE];
! 	      ++__beg;
! 	      
  	      // Remove optional plus or minus sign, if they exist.
! 	      if (__beg != __end)
  		{
! 		  const bool __plus = __traits_type::eq(*__beg, __lit[_S_iplus]);
! 		  if (__plus || __traits_type::eq(*__beg, __lit[_S_iminus]))
! 		    {
! 		      __xtrc += __plus ? _S_atoms_in[_S_iplus] 
! 			               : _S_atoms_in[_S_iminus];
! 		      ++__beg;
! 		    }
  		}
  	      __found_sci = true;
  	    }
*************** namespace std
*** 288,342 ****
  	__base = 10;
  
        // First check for sign.
!       char_type  __c = *__beg;
!       const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]);
!       if ((__plus || __traits_type::eq(__c, __lit[_S_iminus])) 
! 	  && __beg != __end)
  	{
! 	  __xtrc += __plus ? _S_atoms_in[_S_iplus] : _S_atoms_in[_S_iminus];
! 	  __c = *(++__beg);
  	}
  
!       // Next, strip leading zeros and check required digits for base formats.
!       if (__base == 10)
  	{
! 	  bool __found_zero = false;
! 	  while (__traits_type::eq(__c, __lit[_S_izero]) && __beg != __end)
! 	    {
! 	      __c = *(++__beg);
! 	      __found_zero = true;
! 	    }
! 	  if (__found_zero)
  	    {
  	      __xtrc += _S_atoms_in[_S_izero];
! 	      if (__basefield == 0)
! 		{	      
! 		  const bool __x = __traits_type::eq(__c, __lit[_S_ix]);
! 		  if ((__x || __traits_type::eq(__c, __lit[_S_iX]))
! 		      && __beg != __end)
  		    {
! 		      __xtrc += __x ? _S_atoms_in[_S_ix] : _S_atoms_in[_S_iX];
! 		      __c = *(++__beg);
  		      __base = 16;
  		    }
  		  else 
  		    __base = 8;
! 		}
  	    }
  	}
        else if (__base == 16)
  	{
! 	  if (__traits_type::eq(__c, __lit[_S_izero]) && __beg != __end)
  	    {
  	      __xtrc += _S_atoms_in[_S_izero];
! 	      __c = *(++__beg); 
! 
! 	      const bool __x = __traits_type::eq(__c, __lit[_S_ix]);
! 	      if ((__x || __traits_type::eq(__c, __lit[_S_iX]))
! 		  && __beg != __end)
  		{
! 		  __xtrc += __x ? _S_atoms_in[_S_ix] : _S_atoms_in[_S_iX];
! 		  __c = *(++__beg);
  		}
  	    }
  	}
--- 287,348 ----
  	__base = 10;
  
        // First check for sign.
!       if (__beg != __end)
  	{
! 	  const char_type __c = *__beg;
! 	  const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]);
! 	  if (__plus || __traits_type::eq(__c, __lit[_S_iminus]))
! 	    {
! 	      __xtrc += __plus ? _S_atoms_in[_S_iplus]
! 		               : _S_atoms_in[_S_iminus];
! 	      ++__beg;
! 	    }
  	}
  
!       // Next, look for leading zeros and check required digits for base formats.
!       if (__builtin_expect(__base == 10, true))
  	{
! 	  // Look for a zero...
! 	  if (__beg != __end && __traits_type::eq(*__beg, __lit[_S_izero]))
  	    {
  	      __xtrc += _S_atoms_in[_S_izero];
! 	      ++__beg;
! 	      // ... and skip the additional ones.
! 	      for (; __beg != __end
! 		     && __traits_type::eq(*__beg, __lit[_S_izero]); ++__beg);
! 	      
! 	      // Check required digits.
! 	      if (__beg != __end && __basefield == 0)
! 		{	  
! 		  const bool __x = __traits_type::eq(*__beg, __lit[_S_ix]);
! 		  if (__x || __traits_type::eq(*__beg, __lit[_S_iX]))
  		    {
! 		      __xtrc += __x ? _S_atoms_in[_S_ix] 
! 			            : _S_atoms_in[_S_iX];
  		      __base = 16;
+ 		      ++__beg;		      
  		    }
  		  else 
  		    __base = 8;
! 		}	      
  	    }
  	}
        else if (__base == 16)
  	{
! 	  if (__beg != __end && __traits_type::eq(*__beg, __lit[_S_izero]))
  	    {
  	      __xtrc += _S_atoms_in[_S_izero];
! 	      ++__beg; 
! 	      
! 	      if (__beg != __end)
  		{
! 		  const bool __x = __traits_type::eq(*__beg, __lit[_S_ix]);
! 		  if (__x || __traits_type::eq(*__beg, __lit[_S_iX]))
! 		    {
! 		      __xtrc += __x ? _S_atoms_in[_S_ix] 
! 			            : _S_atoms_in[_S_iX];
! 		      ++__beg;
! 		    }
  		}
  	    }
  	}
*************** namespace std
*** 347,368 ****
  
        // Extract.
        string __found_grouping;
-       const char_type __sep = __lc->_M_thousands_sep;
        int __sep_pos = 0;
!       while (__beg != __end)
          {
!           const char_type* __p = __traits_type::find(__lit + _S_izero, 
! 						     __len,  __c);
! 
            // NB: strchr returns true for __c == 0x0
            if (__p && !__traits_type::eq(__c, char_type()))
  	    {
  	      // Try first for acceptable digit; record it if found.
  	      __xtrc += _S_atoms_in[__p - __lit];
  	      ++__sep_pos;
- 	      __c = *(++__beg);
  	    }
!           else if (__traits_type::eq(__c, __sep) && __lc->_M_use_grouping)
  	    {
                // NB: Thousands separator at the beginning of a string
                // is a no-no, as is two consecutive thousands separators.
--- 353,373 ----
  
        // Extract.
        string __found_grouping;
        int __sep_pos = 0;
!       for (; __beg != __end; ++__beg)
          {
! 	  const char_type __c = *__beg;
!           const char_type* __p = __traits_type::find(__lit + _S_izero,
! 						     __len, __c);
            // NB: strchr returns true for __c == 0x0
            if (__p && !__traits_type::eq(__c, char_type()))
  	    {
  	      // Try first for acceptable digit; record it if found.
  	      __xtrc += _S_atoms_in[__p - __lit];
  	      ++__sep_pos;
  	    }
!           else if (__traits_type::eq(__c, __lc->_M_thousands_sep)
! 		   && __lc->_M_use_grouping)
  	    {
                // NB: Thousands separator at the beginning of a string
                // is a no-no, as is two consecutive thousands separators.
*************** namespace std
*** 370,376 ****
                  {
                    __found_grouping += static_cast<char>(__sep_pos);
                    __sep_pos = 0;
- 		  __c = *(++__beg);
                  }
                else
  		{
--- 375,380 ----
diff -prN libstdc++-v3-orig/testsuite/22_locale/num_get/get/char/7.cc libstdc++-v3/testsuite/22_locale/num_get/get/char/7.cc
*** libstdc++-v3-orig/testsuite/22_locale/num_get/get/char/7.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/22_locale/num_get/get/char/7.cc	Sat Oct 25 18:06:50 2003
***************
*** 0 ****
--- 1,58 ----
+ // 2003-10-25  Paolo Carlini  <pcarlini@suse.de>
+ 
+ // Copyright (C) 2003 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.2.1.1  num_get members
+ 
+ #include <locale>
+ #include <sstream>
+ #include <testsuite_hooks.h>
+ 
+ void test01()
+ {
+   using namespace std;
+   typedef istreambuf_iterator<char> iterator_type;
+   
+   bool test __attribute__((unused)) = true;
+ 
+   // cache the num_get facet
+   istringstream iss;
+   const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc()); 
+   ios_base::iostate err = ios_base::goodbit;
+   iterator_type end;
+   double d;
+ 
+   iss.str("+e3");
+   end = ng.get(iss.rdbuf(), 0, iss, err, d);
+   VERIFY( err == ios_base::failbit );
+   VERIFY( *end == 'e' );
+ 
+   iss.str(".e+1");
+   iss.clear();
+   err = ios_base::goodbit;
+   end = ng.get(iss.rdbuf(), 0, iss, err, d);
+   VERIFY( err == ios_base::failbit );
+   VERIFY( *end == 'e' );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/22_locale/num_get/get/wchar_t/7.cc libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/7.cc
*** libstdc++-v3-orig/testsuite/22_locale/num_get/get/wchar_t/7.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/7.cc	Sat Oct 25 18:08:02 2003
***************
*** 0 ****
--- 1,58 ----
+ // 2003-10-25  Paolo Carlini  <pcarlini@suse.de>
+ 
+ // Copyright (C) 2003 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.2.1.1  num_get members
+ 
+ #include <locale>
+ #include <sstream>
+ #include <testsuite_hooks.h>
+ 
+ void test01()
+ {
+   using namespace std;
+   typedef istreambuf_iterator<wchar_t> iterator_type;
+   
+   bool test __attribute__((unused)) = true;
+ 
+   // cache the num_get facet
+   wistringstream iss;
+   const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc()); 
+   ios_base::iostate err = ios_base::goodbit;
+   iterator_type end;
+   double d;
+ 
+   iss.str(L"+e3");
+   end = ng.get(iss.rdbuf(), 0, iss, err, d);
+   VERIFY( err == ios_base::failbit );
+   VERIFY( *end == L'e' );
+ 
+   iss.str(L".e+1");
+   iss.clear();
+   err = ios_base::goodbit;
+   end = ng.get(iss.rdbuf(), 0, iss, err, d);
+   VERIFY( err == ios_base::failbit );
+   VERIFY( *end == L'e' );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
diff -urN libstdc++-v3-1/include/bits/locale_facets.h libstdc++-v3/include/bits/locale_facets.h
--- libstdc++-v3-1/include/bits/locale_facets.h	2003-10-22 21:51:11.000000000 +0200
+++ libstdc++-v3/include/bits/locale_facets.h	2003-10-27 14:23:42.000000000 +0100
@@ -125,7 +125,7 @@
   template<typename _CharT>
     bool
     __verify_grouping(const basic_string<_CharT>& __grouping, 
-		      basic_string<_CharT>& __grouping_tmp);
+		      const basic_string<_CharT>& __grouping_tmp);
 
   // Used by both numeric and monetary facets.
   // Inserts "group separator" characters into an array of characters.
diff -urN libstdc++-v3-1/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-1/include/bits/locale_facets.tcc	2003-10-26 09:11:15.000000000 +0100
+++ libstdc++-v3/include/bits/locale_facets.tcc	2003-10-27 14:06:59.000000000 +0100
@@ -1613,6 +1613,18 @@
 		  _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2, 
 				 __ctype, __err);
 		  break;
+		case 'e':
+		  // Day [1, 31], with single digits preceded by
+		  // space. [tm_mday]
+		  if (__ctype.is(ctype_base::space, *__beg))
+		    _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9, 1,
+				   __ctype, __err);
+		  else if (*__beg != __ctype.widen('0'))
+		    _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31, 2,
+				   __ctype, __err);		    
+		  else
+		    __err |= ios_base::failbit;
+		  break;		    
 		case 'D':
 		  // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year]
 		  __cs = "%m/%d/%y";
@@ -1664,7 +1676,7 @@
 		  if (__ctype.narrow(*__beg, 0) == '\t')
 		    ++__beg;
 		  else
-		__err |= ios_base::failbit;
+		    __err |= ios_base::failbit;
 		  break;
 		case 'T':
 		  // Equivalent to (%H:%M:%S).
@@ -1711,10 +1723,9 @@
 				      14, __err);
 		      
 		      // GMT requires special effort.
-		      char_type __c = *__beg;
-		      if (!__err && __tmp == 0 
-			  && (__c == __ctype.widen('-') 
-			      || __c == __ctype.widen('+')))
+		      if (__beg != __end && !__err && __tmp == 0
+			  && (*__beg == __ctype.widen('-') 
+			      || *__beg == __ctype.widen('+')))
 			{
 			  _M_extract_num(__beg, __end, __tmp, 0, 23, 2,
 					  __ctype, __err);
@@ -2249,7 +2260,7 @@
   template<typename _CharT>
     bool
     __verify_grouping(const basic_string<_CharT>& __grouping, 
-		      basic_string<_CharT>& __grouping_tmp)
+		      const basic_string<_CharT>& __grouping_tmp)
     {         
       size_t __i = 0;
       size_t __j = 0;
diff -urN libstdc++-v3-1/src/locale-inst.cc libstdc++-v3/src/locale-inst.cc
--- libstdc++-v3-1/src/locale-inst.cc	2003-10-22 22:46:40.000000000 +0200
+++ libstdc++-v3/src/locale-inst.cc	2003-10-27 14:10:31.000000000 +0100
@@ -233,7 +233,8 @@
 
   template
     bool
-    __verify_grouping<C>(const basic_string<C>&, basic_string<C>&);
+    __verify_grouping<C>(const basic_string<C>&,
+			 const basic_string<C>&);
 
   template class __pad<C, char_traits<C> >;
 
diff -urN libstdc++-v3-1/testsuite/22_locale/time_get/get_date/char/12750.cc libstdc++-v3/testsuite/22_locale/time_get/get_date/char/12750.cc
--- libstdc++-v3-1/testsuite/22_locale/time_get/get_date/char/12750.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/time_get/get_date/char/12750.cc	2003-10-27 11:57:44.000000000 +0100
@@ -0,0 +1,79 @@
+// 2003-10-27 Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2003 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.5.1.1 time_get members
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/12750
+void test01()
+{
+  using namespace std;
+  typedef istreambuf_iterator<char> iterator_type;
+
+  bool test __attribute__((unused)) = true;
+
+  // basic construction
+  locale loc_is = __gnu_test::try_named_locale("is_IS");
+
+  // create an ostream-derived object, cache the time_get facet
+  iterator_type end;
+
+  istringstream iss;
+  const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc()); 
+
+  const ios_base::iostate good = ios_base::goodbit;
+  ios_base::iostate errorstate = good;
+
+  // create "C" time objects
+  const tm time_bday01 = { 0, 0, 12, 2, 9, 103, 4, 274, -1 };
+  const tm time_bday02 = { 0, 0, 12, 26, 9, 103, 0, 298, -1 };
+
+  // inspection of named locales, is_IS
+  iss.imbue(loc_is);
+
+  iss.str("Fim  2.Okt 2003");
+  iterator_type is_it01(iss);
+  tm time01;
+  errorstate = good;
+  tim_get.get_date(is_it01, end, iss, errorstate, &time01);
+  VERIFY( time01.tm_mon == time_bday01.tm_mon );
+  VERIFY( time01.tm_mday == time_bday01.tm_mday );
+  VERIFY( time01.tm_year == time_bday01.tm_year );
+  VERIFY( errorstate == ios_base::eofbit );
+
+  iss.str("Sun 26.Okt 2003");
+  iterator_type is_it02(iss);
+  tm time02;
+  errorstate = good;
+  tim_get.get_date(is_it02, end, iss, errorstate, &time02);
+  VERIFY( time02.tm_mon == time_bday02.tm_mon );
+  VERIFY( time02.tm_mday == time_bday02.tm_mday );
+  VERIFY( time02.tm_year == time_bday02.tm_year );
+  VERIFY( errorstate == ios_base::eofbit );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-1/testsuite/22_locale/time_get/get_date/wchar_t/12750.cc libstdc++-v3/testsuite/22_locale/time_get/get_date/wchar_t/12750.cc
--- libstdc++-v3-1/testsuite/22_locale/time_get/get_date/wchar_t/12750.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/22_locale/time_get/get_date/wchar_t/12750.cc	2003-10-27 11:58:03.000000000 +0100
@@ -0,0 +1,79 @@
+// 2003-10-27 Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2003 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.5.1.1 time_get members
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/12750
+void test01()
+{
+  using namespace std;
+  typedef istreambuf_iterator<wchar_t> iterator_type;
+
+  bool test __attribute__((unused)) = true;
+
+  // basic construction
+  locale loc_is = __gnu_test::try_named_locale("is_IS");
+
+  // create an ostream-derived object, cache the time_get facet
+  iterator_type end;
+
+  wistringstream iss;
+  const time_get<wchar_t>& tim_get = use_facet<time_get<wchar_t> >(iss.getloc()); 
+
+  const ios_base::iostate good = ios_base::goodbit;
+  ios_base::iostate errorstate = good;
+
+  // create "C" time objects
+  const tm time_bday01 = { 0, 0, 12, 2, 9, 103, 4, 274, -1 };
+  const tm time_bday02 = { 0, 0, 12, 26, 9, 103, 0, 298, -1 };
+
+  // inspection of named locales, is_IS
+  iss.imbue(loc_is);
+
+  iss.str(L"Fim  2.Okt 2003");
+  iterator_type is_it01(iss);
+  tm time01;
+  errorstate = good;
+  tim_get.get_date(is_it01, end, iss, errorstate, &time01);
+  VERIFY( time01.tm_mon == time_bday01.tm_mon );
+  VERIFY( time01.tm_mday == time_bday01.tm_mday );
+  VERIFY( time01.tm_year == time_bday01.tm_year );
+  VERIFY( errorstate == ios_base::eofbit );
+
+  iss.str(L"Sun 26.Okt 2003");
+  iterator_type is_it02(iss);
+  tm time02;
+  errorstate = good;
+  tim_get.get_date(is_it02, end, iss, errorstate, &time02);
+  VERIFY( time02.tm_mon == time_bday02.tm_mon );
+  VERIFY( time02.tm_mday == time_bday02.tm_mday );
+  VERIFY( time02.tm_year == time_bday02.tm_year );
+  VERIFY( errorstate == ios_base::eofbit );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]