[v3] time_get::_M_extract_names and capitalized names

Benjamin Kosnik bkoz@redhat.com
Tue Nov 4 02:06:00 GMT 2003


On some glibc's the localedata for various locales (is_IS, fr_FR,
etc.) is all lowercase, and on others (C, de_DE) it's first letter
capitalized, then lowercase.

This change allows either form to be used, and fixed a spurious
failure with

22_locale/time_get/get_date/char/12750.cc
22_locale/time_get/get_date/wchar_t/12750.cc

on linux machines with is_IS localedata in the lowercase form.

tested x86/linux

2003-11-03  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/locale_facets.h (time_get::_M_extract_name): Add
	ctype argument.	
	* include/bits/locale_facets.tcc: Same, use it to allow
	capitalized names.
	
	* include/bits/fstream.tcc: Spacing tweak.
	* include/bits/istream.tcc: Same.
	* include/bits/ostream.tcc: Same.

Index: include/bits/fstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.103
diff -c -p -r1.103 fstream.tcc
*** include/bits/fstream.tcc	16 Oct 2003 22:37:50 -0000	1.103
--- include/bits/fstream.tcc	4 Nov 2003 01:55:02 -0000
*************** namespace std
*** 610,616 ****
  		  __computed_off += _M_ext_buf + __gptr_off - _M_ext_end;
  		}
  	    }
- 	  
  	  __ret = _M_seek(__computed_off, __way);
  	}
        _M_last_overflowed = false;	
--- 610,615 ----
Index: include/bits/istream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/istream.tcc,v
retrieving revision 1.52
diff -c -p -r1.52 istream.tcc
*** include/bits/istream.tcc	12 Oct 2003 10:12:08 -0000	1.52
--- include/bits/istream.tcc	4 Nov 2003 01:55:02 -0000
*************** namespace std 
*** 63,69 ****
  		  __c = __sb->snextc();
  
  	      // _GLIBCXX_RESOLVE_LIB_DEFECTS
! 	      // 195. Should basic_istream::sentry's constructor ever set eofbit? 
  	      if (traits_type::eq_int_type(__c, __eof))
  		__in.setstate(ios_base::eofbit);
  	    }
--- 63,70 ----
  		  __c = __sb->snextc();
  
  	      // _GLIBCXX_RESOLVE_LIB_DEFECTS
! 	      // 195. Should basic_istream::sentry's constructor ever
! 	      // 195. set eofbit?
  	      if (traits_type::eq_int_type(__c, __eof))
  		__in.setstate(ios_base::eofbit);
  	    }
Index: include/bits/locale_facets.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.h,v
retrieving revision 1.69
diff -c -p -r1.69 locale_facets.h
*** include/bits/locale_facets.h	27 Oct 2003 16:21:12 -0000	1.69
--- include/bits/locale_facets.h	4 Nov 2003 01:55:03 -0000
*************** namespace std
*** 1519,1524 ****
--- 1519,1525 ----
        void
        _M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
  		      const _CharT** __names, size_t __indexlen, 
+ 		      const ctype<_CharT>& __ctype, 
  		      ios_base::iostate& __err) const;
  
        // Extract on a component-by-component basis, via __format argument.
Index: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.141
diff -c -p -r1.141 locale_facets.tcc
*** include/bits/locale_facets.tcc	30 Oct 2003 09:03:01 -0000	1.141
--- include/bits/locale_facets.tcc	4 Nov 2003 01:55:04 -0000
*************** namespace std
*** 1533,1539 ****
  			  const _CharT* __format) const
      {  
        const locale __loc = __io.getloc();
!       __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
        const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); 
        const size_t __len = char_traits<_CharT>::length(__format);
  
--- 1533,1539 ----
  			  const _CharT* __format) const
      {  
        const locale __loc = __io.getloc();
!       const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
        const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); 
        const size_t __len = char_traits<_CharT>::length(__format);
  
*************** namespace std
*** 1556,1569 ****
  		  const char_type*  __days1[7];
  		  __tp._M_days_abbreviated(__days1);
  		  _M_extract_name(__beg, __end, __tm->tm_wday, __days1, 7, 
! 				  __err);
  		  break;
  		case 'A':
  		  // Weekday name [tm_wday].
  		  const char_type*  __days2[7];
  		  __tp._M_days(__days2);
  		  _M_extract_name(__beg, __end, __tm->tm_wday, __days2, 7, 
! 				  __err);
  		  break;
  		case 'h':
  		case 'b':
--- 1556,1569 ----
  		  const char_type*  __days1[7];
  		  __tp._M_days_abbreviated(__days1);
  		  _M_extract_name(__beg, __end, __tm->tm_wday, __days1, 7, 
! 				  __ctype, __err);
  		  break;
  		case 'A':
  		  // Weekday name [tm_wday].
  		  const char_type*  __days2[7];
  		  __tp._M_days(__days2);
  		  _M_extract_name(__beg, __end, __tm->tm_wday, __days2, 7, 
! 				  __ctype, __err);
  		  break;
  		case 'h':
  		case 'b':
*************** namespace std
*** 1571,1584 ****
  		  const char_type*  __months1[12];
  		  __tp._M_months_abbreviated(__months1);
  		  _M_extract_name(__beg, __end, __tm->tm_mon, __months1, 12, 
! 				  __err);
  		  break;
  		case 'B':
  		  // Month name [tm_mon].
  		  const char_type*  __months2[12];
  		  __tp._M_months(__months2);
  		  _M_extract_name(__beg, __end, __tm->tm_mon, __months2, 12, 
! 				  __err);
  		  break;
  		case 'c':
  		  // Default time and date representation.
--- 1571,1584 ----
  		  const char_type*  __months1[12];
  		  __tp._M_months_abbreviated(__months1);
  		  _M_extract_name(__beg, __end, __tm->tm_mon, __months1, 12, 
! 				  __ctype, __err);
  		  break;
  		case 'B':
  		  // Month name [tm_mon].
  		  const char_type*  __months2[12];
  		  __tp._M_months(__months2);
  		  _M_extract_name(__beg, __end, __tm->tm_mon, __months2, 12, 
! 				  __ctype, __err);
  		  break;
  		case 'c':
  		  // Default time and date representation.
*************** namespace std
*** 1697,1703 ****
  		      int __tmp;
  		      _M_extract_name(__beg, __end, __tmp, 
  				      __timepunct_cache<_CharT>::_S_timezones, 
! 				      14, __err);
  		      
  		      // GMT requires special effort.
  		      if (__beg != __end && !__err && __tmp == 0
--- 1697,1703 ----
  		      int __tmp;
  		      _M_extract_name(__beg, __end, __tmp, 
  				      __timepunct_cache<_CharT>::_S_timezones, 
! 				      14, __ctype, __err);
  		      
  		      // GMT requires special effort.
  		      if (__beg != __end && !__err && __tmp == 0
*************** namespace std
*** 1764,1769 ****
--- 1764,1770 ----
      time_get<_CharT, _InIter>::
      _M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
  		    const _CharT** __names, size_t __indexlen, 
+ 		    const ctype<_CharT>& __ctype, 
  		    ios_base::iostate& __err) const
      {
        typedef char_traits<_CharT> 		__traits_type;
*************** namespace std
*** 1774,1785 ****
        bool __testvalid = true;
        const char_type* __name;
  
!       // Look for initial matches.
        if (__beg != __end)
  	{
  	  const char_type __c = *__beg;
  	  for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
! 	    if (__c == __names[__i1][0])
  	      __matches[__nmatches++] = __i1;
  	}
        
--- 1775,1790 ----
        bool __testvalid = true;
        const char_type* __name;
  
!       // Look for initial matches.  
!       // NB: Some of the locale data is in the form of all lowercase
!       // names, and some is in the form of initially-capitalized
!       // names. Look for both.
        if (__beg != __end)
  	{
  	  const char_type __c = *__beg;
  	  for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
! 	    if (__c == __names[__i1][0] 
! 		|| __c == __ctype.toupper(__names[__i1][0]))
  	      __matches[__nmatches++] = __i1;
  	}
        
*************** namespace std
*** 1807,1812 ****
--- 1812,1824 ----
  
        if (__nmatches == 1)
  	{
+ 	  // If there was only one match, the first compare is redundant.
+ 	  if (__pos == 0)
+ 	    {
+ 	      ++__pos;
+ 	      ++__beg;
+ 	    }
+ 
  	  // Make sure found name is completely extracted.
  	  __name = __names[__matches[0]];
  	  const size_t __len = __traits_type::length(__name);
*************** namespace std
*** 1866,1876 ****
      {
        typedef char_traits<_CharT> 		__traits_type;
        const locale __loc = __io.getloc();
!       __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
        const char_type*  __days[7];
        __tp._M_days_abbreviated(__days);
        int __tmpwday;
!       _M_extract_name(__beg, __end, __tmpwday, __days, 7, __err);
  
        // Check to see if non-abbreviated name exists, and extract.
        // NB: Assumes both _M_days and _M_days_abbreviated organized in
--- 1878,1889 ----
      {
        typedef char_traits<_CharT> 		__traits_type;
        const locale __loc = __io.getloc();
!       const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
!       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); 
        const char_type*  __days[7];
        __tp._M_days_abbreviated(__days);
        int __tmpwday;
!       _M_extract_name(__beg, __end, __tmpwday, __days, 7, __ctype, __err);
  
        // Check to see if non-abbreviated name exists, and extract.
        // NB: Assumes both _M_days and _M_days_abbreviated organized in
*************** namespace std
*** 1909,1919 ****
      {
        typedef char_traits<_CharT> 		__traits_type;
        const locale __loc = __io.getloc();
!       __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
        const char_type*  __months[12];
        __tp._M_months_abbreviated(__months);
        int __tmpmon;
!       _M_extract_name(__beg, __end, __tmpmon, __months, 12, __err);
  
        // Check to see if non-abbreviated name exists, and extract.
        // NB: Assumes both _M_months and _M_months_abbreviated organized in
--- 1922,1933 ----
      {
        typedef char_traits<_CharT> 		__traits_type;
        const locale __loc = __io.getloc();
!       const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
!       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); 
        const char_type*  __months[12];
        __tp._M_months_abbreviated(__months);
        int __tmpmon;
!       _M_extract_name(__beg, __end, __tmpmon, __months, 12, __ctype, __err);
  
        // Check to see if non-abbreviated name exists, and extract.
        // NB: Assumes both _M_months and _M_months_abbreviated organized in
Index: include/bits/ostream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/ostream.tcc,v
retrieving revision 1.45
diff -c -p -r1.45 ostream.tcc
*** include/bits/ostream.tcc	12 Oct 2003 10:12:08 -0000	1.45
--- include/bits/ostream.tcc	4 Nov 2003 01:55:04 -0000
*************** namespace std 
*** 673,680 ****
  	  // 25. String operator<< uses width() value wrong
  	  if (__w > __len)
  	    {
! 	      _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
! 								   * __w));
  	      __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s,
  					     __w, __len, false);
  	      __s = __cs;
--- 673,679 ----
  	  // 25. String operator<< uses width() value wrong
  	  if (__w > __len)
  	    {
! 	      _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
  	      __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s,
  					     __w, __len, false);
  	      __s = __cs;



More information about the Gcc-patches mailing list