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]

[Patch] Simplify config/locale/*/numeric & monetary as per Martin'shint


Hi,

the below implements Martin's nice advice of a few days ago: basically
all the involved chars definitely belong to the "basic character set",
no need to call btowc. I like the "C" locale path being now so neat!

Tested x86-linux gnu/generic, will commit later today.

Paolo.

/////////////
2004-04-15  Paolo Carlini  <pcarlini@suse.de>

	* config/locale/generic/monetary_members.cc
	(moneypunct<wchar_t>::_M_initialize_moneypunct): Avoid calling
	btowc unnecessarily, just cast to wchar_t (the concerned chars
	all belong to the basic character set).
	* config/locale/generic/numeric_members.cc
	(numpunct<wchar_t>::_M_initialize_numpunct): Likewise.
	* config/locale/gnu/monetary_members.cc
	(moneypunct<wchar_t>::_M_initialize_moneypunct): Likewise.
	* config/locale/gnu/numeric_members.cc
	(numpunct<wchar_t>::_M_initialize_numpunct): Likewise.	
diff -urN libstdc++-v3-orig/config/locale/generic/monetary_members.cc libstdc++-v3/config/locale/generic/monetary_members.cc
--- libstdc++-v3-orig/config/locale/generic/monetary_members.cc	2004-02-21 10:26:33.000000000 +0100
+++ libstdc++-v3/config/locale/generic/monetary_members.cc	2004-04-15 10:48:06.000000000 +0200
@@ -127,12 +127,9 @@
       _M_data->_M_pos_format = money_base::_S_default_pattern;
       _M_data->_M_neg_format = money_base::_S_default_pattern;
 
-      unsigned char uc;
       for (size_t __i = 0; __i < money_base::_S_end; ++__i)
-	{
-	  uc = static_cast<unsigned char>(money_base::_S_atoms[__i]);
-	  _M_data->_M_atoms[__i] = btowc(uc);
-	}
+	_M_data->_M_atoms[__i] =
+	  static_cast<wchar_t>(money_base::_S_atoms[__i]);
     }
 
   template<> 
@@ -158,12 +155,9 @@
       _M_data->_M_pos_format = money_base::_S_default_pattern;
       _M_data->_M_neg_format = money_base::_S_default_pattern;
 
-      unsigned char uc;
       for (size_t __i = 0; __i < money_base::_S_end; ++__i)
-	{
-	  uc = static_cast<unsigned char>(money_base::_S_atoms[__i]);
-	  _M_data->_M_atoms[__i] = btowc(uc);
-	}
+	_M_data->_M_atoms[__i] =
+	  static_cast<wchar_t>(money_base::_S_atoms[__i]);
     }
 
   template<> 
diff -urN libstdc++-v3-orig/config/locale/generic/numeric_members.cc libstdc++-v3/config/locale/generic/numeric_members.cc
--- libstdc++-v3-orig/config/locale/generic/numeric_members.cc	2004-02-21 10:26:33.000000000 +0100
+++ libstdc++-v3/config/locale/generic/numeric_members.cc	2004-04-15 11:27:47.000000000 +0200
@@ -59,9 +59,9 @@
 	_M_data->_M_atoms_in[__i] = __num_base::_S_atoms_in[__i];
 
       _M_data->_M_truename = "true";
-      _M_data->_M_truename_size = strlen(_M_data->_M_truename);
+      _M_data->_M_truename_size = 4;
       _M_data->_M_falsename = "false";
-      _M_data->_M_falsename_size = strlen(_M_data->_M_falsename);
+      _M_data->_M_falsename_size = 5;
     }
 
   template<> 
@@ -85,23 +85,18 @@
       _M_data->_M_thousands_sep = L',';
       
       // Use ctype::widen code without the facet...
-      unsigned char uc;
       for (size_t __i = 0; __i < __num_base::_S_oend; ++__i)
-	{
-	  uc = static_cast<unsigned char>(__num_base::_S_atoms_out[__i]);
-	  _M_data->_M_atoms_out[__i] = btowc(uc);
-	}
+	_M_data->_M_atoms_out[__i] =
+	  static_cast<wchar_t>(__num_base::_S_atoms_out[__i]);
       
       for (size_t __i = 0; __i < __num_base::_S_iend; ++__i)
-	{
-	  uc = static_cast<unsigned char>(__num_base::_S_atoms_in[__i]);
-	  _M_data->_M_atoms_in[__i] = btowc(uc);
-	}
+	_M_data->_M_atoms_in[__i] =
+	  static_cast<wchar_t>(__num_base::_S_atoms_in[__i]);
 
       _M_data->_M_truename = L"true";
-      _M_data->_M_truename_size = wcslen(_M_data->_M_truename);
+      _M_data->_M_truename_size = 4;
       _M_data->_M_falsename = L"false";
-      _M_data->_M_falsename_size = wcslen(_M_data->_M_falsename);
+      _M_data->_M_falsename_size = 5;
     }
 
   template<> 
diff -urN libstdc++-v3-orig/config/locale/gnu/monetary_members.cc libstdc++-v3/config/locale/gnu/monetary_members.cc
--- libstdc++-v3-orig/config/locale/gnu/monetary_members.cc	2004-04-07 16:32:46.000000000 +0200
+++ libstdc++-v3/config/locale/gnu/monetary_members.cc	2004-04-15 10:46:17.000000000 +0200
@@ -372,12 +372,9 @@
 	  _M_data->_M_neg_format = money_base::_S_default_pattern;
 
 	  // Use ctype::widen code without the facet...
-	  unsigned char uc;
 	  for (size_t __i = 0; __i < money_base::_S_end; ++__i)
-	    {
-	      uc = static_cast<unsigned char>(money_base::_S_atoms[__i]);
-	      _M_data->_M_atoms[__i] = btowc(uc);
-	    }
+	    _M_data->_M_atoms[__i] =
+	      static_cast<wchar_t>(money_base::_S_atoms[__i]);
 	}
       else
 	{
@@ -517,12 +514,9 @@
 	  _M_data->_M_neg_format = money_base::_S_default_pattern;
 
 	  // Use ctype::widen code without the facet...
-	  unsigned char uc;
 	  for (size_t __i = 0; __i < money_base::_S_end; ++__i)
-	    {
-	      uc = static_cast<unsigned char>(money_base::_S_atoms[__i]);
-	      _M_data->_M_atoms[__i] = btowc(uc);
-	    }
+	    _M_data->_M_atoms[__i] =
+	      static_cast<wchar_t>(money_base::_S_atoms[__i]);
 	}
       else
 	{
diff -urN libstdc++-v3-orig/config/locale/gnu/numeric_members.cc libstdc++-v3/config/locale/gnu/numeric_members.cc
--- libstdc++-v3-orig/config/locale/gnu/numeric_members.cc	2004-04-11 17:04:45.000000000 +0200
+++ libstdc++-v3/config/locale/gnu/numeric_members.cc	2004-04-15 11:28:30.000000000 +0200
@@ -78,10 +78,10 @@
       // NB: There is no way to extact this info from posix locales.
       // _M_truename = __nl_langinfo_l(YESSTR, __cloc);
       _M_data->_M_truename = "true";
-      _M_data->_M_truename_size = strlen(_M_data->_M_truename);
+      _M_data->_M_truename_size = 4;
       // _M_falsename = __nl_langinfo_l(NOSTR, __cloc);
       _M_data->_M_falsename = "false";
-      _M_data->_M_falsename_size = strlen(_M_data->_M_falsename);
+      _M_data->_M_falsename_size = 5;
     }
  
   template<> 
@@ -107,18 +107,13 @@
 	  _M_data->_M_thousands_sep = L',';
 
 	  // Use ctype::widen code without the facet...
-	  unsigned char uc;
 	  for (size_t __i = 0; __i < __num_base::_S_oend; ++__i)
-	    {
-	      uc = static_cast<unsigned char>(__num_base::_S_atoms_out[__i]);
-	      _M_data->_M_atoms_out[__i] = btowc(uc);
-	    }
+	    _M_data->_M_atoms_out[__i] =
+	      static_cast<wchar_t>(__num_base::_S_atoms_out[__i]);
 
 	  for (size_t __i = 0; __i < __num_base::_S_iend; ++__i)
-	    {
-	      uc = static_cast<unsigned char>(__num_base::_S_atoms_in[__i]);
-	      _M_data->_M_atoms_in[__i] = btowc(uc);
-	    }
+	    _M_data->_M_atoms_in[__i] =
+	      static_cast<wchar_t>(__num_base::_S_atoms_in[__i]);
 	}
       else
 	{
@@ -140,10 +135,10 @@
       // NB: There is no way to extact this info from posix locales.
       // _M_truename = __nl_langinfo_l(YESSTR, __cloc);
       _M_data->_M_truename = L"true";
-      _M_data->_M_truename_size = wcslen(_M_data->_M_truename);
+      _M_data->_M_truename_size = 4;
       // _M_falsename = __nl_langinfo_l(NOSTR, __cloc);
       _M_data->_M_falsename = L"false";
-      _M_data->_M_falsename_size = wcslen(_M_data->_M_falsename);
+      _M_data->_M_falsename_size = 5;
     }
 
   template<> 

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