This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Re: [RFC] libstdc++/9817 or "passing C++ strings to C functions"


Paolo Carlini wrote:

Now, I have got an idea: what about substituting a conventional char
for the original '\0' (f.i., '$') and then calling strcoll (strxfrm,
respectively) as usual?

For concreteness, you will find attached a *very* rough and redundant (please, be gentle ;) implementation of the idea. I'm still not sure if this is allowed by the standard and if less costly solutions are worthy (for instance calling the underlying strcoll more than one time for each hunk).

Paolo.
*** locale_facets.tcc.~1.92.~	Fri Feb 21 13:43:07 2003
--- locale_facets.tcc	Sun Feb 23 17:19:18 2003
*************** namespace std
*** 2038,2045 ****
      do_compare(const _CharT* __lo1, const _CharT* __hi1, 
  	       const _CharT* __lo2, const _CharT* __hi2) const
      { 
!       const string_type __one(__lo1, __hi1);
!       const string_type __two(__lo2, __hi2);
        return _M_compare(__one.c_str(), __two.c_str());
      }
  
--- 2038,2069 ----
      do_compare(const _CharT* __lo1, const _CharT* __hi1, 
  	       const _CharT* __lo2, const _CharT* __hi2) const
      { 
!       typedef char_traits<_CharT>  __traits_type;
!       string_type __one(__lo1, __hi1);
!       string_type __two(__lo2, __hi2);
! 
!       const _CharT* __pos = __lo1;
!       while (__pos != __hi1)
! 	{
! 	  __pos =
! 	    __traits_type::find(__pos, __hi1 - __pos, _CharT('\0'));
! 	  if (__pos)
! 	    __one[__pos++ - __lo1] = _CharT('$');
! 	  else
! 	    break;
! 	}
! 
!       __pos = __lo2;
!       while (__pos != __hi2)
! 	{
! 	  __pos =
! 	    __traits_type::find(__pos, __hi2 - __pos, _CharT('\0'));
! 	  if (__pos)
! 	    __two[__pos++ - __lo2] = _CharT('$');
! 	  else
! 	    break;
! 	}
! 
        return _M_compare(__one.c_str(), __two.c_str());
      }
  

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