ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2005/05/31/18:16:58

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Carey Evans" <carey DOT evans AT gmail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Bugs fixes for G++ ctype<char> specialisation
Date: 31 May 2005 15:11:26 -0700
Organization: http://groups.google.com
Lines: 113
Message-ID: <1117577486.704501.203930@z14g2000cwz.googlegroups.com>
NNTP-Posting-Host: 210.54.0.162
Mime-Version: 1.0
X-Trace: posting.google.com 1117577492 3482 127.0.0.1 (31 May 2005 22:11:32 GMT)
X-Complaints-To: groups-abuse AT google DOT com
NNTP-Posting-Date: Tue, 31 May 2005 22:11:32 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: groups-abuse AT google DOT com
Injection-Info: z14g2000cwz.googlegroups.com; posting-host=210.54.0.162;
posting-account=a2Dz9g0AAAAQI7DN4N6e935Thq5XWCRh
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

The patch below changes ctype_inline.h and ctype_nonline.h to work in
line with the C++ standard, section 22.2.1.3.  Currently is(mask,char),
scan_is() and scan_not() don't follow the spec and only work for the
classic ctype table, is(const char*,const char*,mask*) doesn't work
anyway, and do_tolower() and do_toupper() don't work for non-ASCII
characters.

This patch makes the DJGPP versions of ctype_inline.h and
ctype_noninline.h almost identical to the Solaris versions, apart from
the names of the pointers to the ctype flags, tolower and toupper
tables.

diff -u -r bits.dist/ctype_inline.h bits/ctype_inline.h
--- bits.dist/ctype_inline.h	2004-11-06 16:21:54.000000000 +1300
+++ bits/ctype_inline.h	2005-06-01 09:53:08.000000000 +1200
@@ -37,7 +37,7 @@
   bool
   ctype<char>::
   is(mask __m, char __c) const
-  { return _M_table[static_cast<unsigned char>(__c + 1)] & __m; }
+  { return _M_table[static_cast<unsigned char>(__c)] & __m; }

   const char*
   ctype<char>::
@@ -52,7 +52,8 @@
   ctype<char>::
   scan_is(mask __m, const char* __low, const char* __high) const
   {
-    while (__low < __high && !this->is(__m, *__low))
+    while (__low < __high
+           && !(_M_table[static_cast<unsigned char>(*__low)] & __m))
       ++__low;
     return __low;
   }
@@ -61,7 +62,8 @@
   ctype<char>::
   scan_not(mask __m, const char* __low, const char* __high) const
   {
-    while (__low < __high && this->is(__m, *__low) != 0)
+    while (__low < __high
+           && (_M_table[static_cast<unsigned char>(*__low)] & __m) !=
0)
       ++__low;
     return __low;
   }
diff -u -r bits.dist/ctype_noninline.h bits/ctype_noninline.h
--- bits.dist/ctype_noninline.h	2004-11-06 16:21:54.000000000 +1300
+++ bits/ctype_noninline.h	2005-06-01 09:56:38.000000000 +1200
@@ -35,13 +35,13 @@

   const ctype_base::mask*
   ctype<char>::classic_table() throw()
-  { return 0; }
+  { return __dj_ctype_flags + 1; }

   ctype<char>::ctype(__c_locale, const mask* __table, bool __del,
 		     size_t __refs)
   : facet(__refs), _M_del(__table != 0 && __del),
-  _M_toupper(__dj_ctype_toupper), _M_tolower(__dj_ctype_tolower),
-  _M_table(__table ? __table : __dj_ctype_flags)
+  _M_toupper(__dj_ctype_toupper + 1), _M_tolower(__dj_ctype_tolower +
1),
+  _M_table(__table ? __table : classic_table())
   {
     memset(_M_widen, 0, sizeof(_M_widen));
     _M_widen_ok = 0;
@@ -51,8 +51,8 @@

   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
   : facet(__refs), _M_del(__table != 0 && __del),
-  _M_toupper(__dj_ctype_toupper), _M_tolower(__dj_ctype_tolower),
-  _M_table(__table ? __table : __dj_ctype_flags)
+  _M_toupper(__dj_ctype_toupper + 1), _M_tolower(__dj_ctype_tolower +
1),
+  _M_table(__table ? __table : classic_table())
   {
     memset(_M_widen, 0, sizeof(_M_widen));
     _M_widen_ok = 0;
@@ -62,14 +62,14 @@

   char
   ctype<char>::do_toupper(char __c) const
-  { return _M_toupper[static_cast<int>(__c)+1]; }
+  { return _M_toupper[static_cast<unsigned char>(__c)]; }

   const char*
   ctype<char>::do_toupper(char* __low, const char* __high) const
   {
     while (__low < __high)
       {
-	*__low = ::toupper(static_cast<int> (*__low));
+	*__low = _M_toupper[static_cast<unsigned char>(*__low)];
 	++__low;
       }
     return __high;
@@ -77,14 +77,14 @@

   char
   ctype<char>::do_tolower(char __c) const
-  { return _M_tolower[static_cast<int>(__c)+1]; }
+  { return _M_tolower[static_cast<unsigned char>(__c)]; }

   const char*
   ctype<char>::do_tolower(char* __low, const char* __high) const
   {
     while (__low < __high)
       {
-	*__low = ::tolower(static_cast<int> (*__low));
+	*__low = _M_tolower[static_cast<unsigned char>(*__low)];
 	++__low;
       }
     return __high;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019