OSDN Git Service

2004-06-18 Paolo Carlini <pcarlini@suse.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / config / locale / gnu / c_locale.cc
index 60ec54d..bf975b9 100644 (file)
@@ -1,6 +1,6 @@
 // Wrapper for underlying C-language localization -*- C++ -*-
 
-// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
 //
 // 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
 
 // Written by Benjamin Kosnik <bkoz@redhat.com>
 
+#include <cerrno>  // For errno
 #include <locale>
 #include <stdexcept>
 #include <langinfo.h>
+#include <bits/c++locale_internal.h>
 
 namespace std 
 {
   template<>
     void
-    __convert_to_v(const char* __s, long& __v, ios_base::iostate& __err, 
-                  const __c_locale& __cloc, int __base)
-    {
-      if (!(__err & ios_base::failbit))
-      {
-       char* __sanity;
-       errno = 0;
-       long __l = __strtol_l(__s, &__sanity, __base, __cloc);
-       if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-         __v = __l;
-       else
-         __err |= ios_base::failbit;
-      }
-    }
-
-  template<>
-    void
-    __convert_to_v(const char* __s, unsigned long& __v, 
-                  ios_base::iostate& __err, const __c_locale& __cloc, 
-                  int __base)
-    {
-      if (!(__err & ios_base::failbit))
-       {
-         char* __sanity;
-         errno = 0;
-         unsigned long __ul = __strtoul_l(__s, &__sanity, __base, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-           __v = __ul;
-         else
-           __err |= ios_base::failbit;
-       }
-    }
-
-#ifdef _GLIBCPP_USE_LONG_LONG
-  template<>
-    void
-    __convert_to_v(const char* __s, long long& __v, ios_base::iostate& __err, 
-                  const __c_locale& __cloc, int __base)
-    {
-      if (!(__err & ios_base::failbit))
-       {
-         char* __sanity;
-         errno = 0;
-         long long __ll = __strtoll_l(__s, &__sanity, __base, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-           __v = __ll;
-         else
-           __err |= ios_base::failbit;
-       }
-    }
-
-  template<>
-    void
-    __convert_to_v(const char* __s, unsigned long long& __v, 
-                  ios_base::iostate& __err, const __c_locale& __cloc, 
-                  int __base)
-    {
-      if (!(__err & ios_base::failbit))
-       {      
-         char* __sanity;
-         errno = 0;
-         unsigned long long __ull = __strtoull_l(__s, &__sanity, __base, 
-                                                 __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
-           __v = __ull;
-         else
-           __err |= ios_base::failbit;
-       }  
-    }
-#endif
-
-  template<>
-    void
     __convert_to_v(const char* __s, float& __v, ios_base::iostate& __err, 
-                  const __c_locale& __cloc, int)
+                  const __c_locale& __cloc)
     {
       if (!(__err & ios_base::failbit))
        {
          char* __sanity;
          errno = 0;
          float __f = __strtof_l(__s, &__sanity, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
+          if (__sanity != __s && errno != ERANGE)
            __v = __f;
          else
            __err |= ios_base::failbit;
@@ -132,14 +61,14 @@ namespace std
   template<>
     void
     __convert_to_v(const char* __s, double& __v, ios_base::iostate& __err, 
-                  const __c_locale& __cloc, int)
+                  const __c_locale& __cloc)
     {
       if (!(__err & ios_base::failbit))
        {
          char* __sanity;
          errno = 0;
          double __d = __strtod_l(__s, &__sanity, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
+          if (__sanity != __s && errno != ERANGE)
            __v = __d;
          else
            __err |= ios_base::failbit;
@@ -149,14 +78,14 @@ namespace std
   template<>
     void
     __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
-                  const __c_locale& __cloc, int)
+                  const __c_locale& __cloc)
     {
       if (!(__err & ios_base::failbit))
        {
          char* __sanity;
          errno = 0;
          long double __ld = __strtold_l(__s, &__sanity, __cloc);
-          if (__sanity != __s && *__sanity == '\0' && errno != ERANGE)
+          if (__sanity != __s && errno != ERANGE)
            __v = __ld;
          else
            __err |= ios_base::failbit;
@@ -171,15 +100,43 @@ namespace std
     if (!__cloc)
       {
        // This named locale is not supported by the underlying OS.
-       __throw_runtime_error("attempt to create locale from unknown name");
+       __throw_runtime_error(__N("locale::facet::_S_create_c_locale "
+                             "name not valid"));
       }
   }
   
   void
   locale::facet::_S_destroy_c_locale(__c_locale& __cloc)
-  { __freelocale(__cloc); }
+  {
+    if (_S_get_c_locale() != __cloc)
+      __freelocale(__cloc); 
+  }
 
   __c_locale
   locale::facet::_S_clone_c_locale(__c_locale& __cloc)
   { return __duplocale(__cloc); }
+} // namespace std
+
+namespace __gnu_cxx
+{
+  const char* const category_names[6 + _GLIBCXX_NUM_CATEGORIES] =
+    {
+      "LC_CTYPE", 
+      "LC_NUMERIC",
+      "LC_TIME", 
+      "LC_COLLATE", 
+      "LC_MONETARY",
+      "LC_MESSAGES", 
+      "LC_PAPER", 
+      "LC_NAME", 
+      "LC_ADDRESS",
+      "LC_TELEPHONE", 
+      "LC_MEASUREMENT", 
+      "LC_IDENTIFICATION" 
+    };
+}
+
+namespace std
+{
+  const char* const* const locale::_S_categories = __gnu_cxx::category_names;
 }  // namespace std