stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r431272 - /incubator/stdcxx/trunk/examples/manual/numpunct.cpp
Date Mon, 14 Aug 2006 00:06:21 GMT
Author: sebor
Date: Sun Aug 13 17:06:21 2006
New Revision: 431272

URL: http://svn.apache.org/viewvc?rev=431272&view=rev
Log:
2006-08-13  Martin Sebor  <sebor@roguewave.com>

	* numpunct.cpp (make_german_locale): New helper function.
	(main): Called it instead of using a hardcoded locale name for each
	known operating system (apparently the names that used to be valid
	on Tru64 UNIX no longer is in 5.1).

Modified:
    incubator/stdcxx/trunk/examples/manual/numpunct.cpp

Modified: incubator/stdcxx/trunk/examples/manual/numpunct.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/manual/numpunct.cpp?rev=431272&r1=431271&r2=431272&view=diff
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/numpunct.cpp (original)
+++ incubator/stdcxx/trunk/examples/manual/numpunct.cpp Sun Aug 13 17:06:21 2006
@@ -2,20 +2,27 @@
  *
  * numpunct.cpp - Example program for the numpunct facet. 
 
- * $Id: //stdlib/dev/examples/stdlib/manual/numpunct.cpp#12 $
+ * $Id$
  *
  ***************************************************************************
  *
- * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
- * Software division. Licensed under the Apache License, Version 2.0 (the
- * "License");  you may  not use this file except  in compliance with the
- * License.    You    may   obtain   a   copy   of    the   License    at
- * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
- * applicable law  or agreed to  in writing,  software  distributed under
- * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
- * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
- * for the specific language governing permissions  and limitations under
- * the License.
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2006 Rogue Wave Software.
  * 
  **************************************************************************/
 
@@ -26,21 +33,45 @@
 #include <examples.h>
 
 
-#if defined (_AIX)
-#  define de_DE "de_DE.ISO8859-1"
-#elif defined (__hpux)
-#  define de_DE "de_DE.iso88591"
-#elif defined (__linux__)
-#  define de_DE "de_DE"
-#elif defined (__osf__)
-#  define de_DE "de_DE.88591"
-#elif defined (SNI)
-#  define de_DE "De_DE.88591"
-#elif defined (_WIN32) || defined (_WIN64)
-#  define de_DE "german_germany.1252"
-#else   // IRIX, SunOS, etc.
-#  define de_DE "de"
-#endif
+static std::locale
+make_german_locale ()
+{
+    static const char* const
+    locale_names [] = {
+        "de_DE.ISO8859-1",       // AIX, Solaris, Tru64
+        "de_DE.iso88591",        // HP-UX, Linux
+        "de_DE.88591",
+        "De_DE.88591",           // Reliant
+        "de_DE",
+        "de",                    // Linux, Solaris
+        "German",
+        "german",                // Linux
+        "deutsch",               // Linux
+        "german_germany.1252",   // Windows
+        0                        // (sentinel)
+    };
+
+    std::locale german;
+
+    // iterate over the know locale names above until a valid one
+    // is found (i.e., one that doesn't cause locale to throw)
+    for (const char* const *names = locale_names; ; ) {
+        try {
+            german = std::locale (names [0]);
+            break;
+        }
+        catch (std::runtime_error&) {
+            // continue trying until the next name is null
+            if (*++names)
+                throw;
+        }
+        catch (...) {
+            throw;
+        }
+    }
+
+    return german;
+}
 
 
 int main ()
@@ -48,11 +79,11 @@
     typedef std::numpunct<char> Numpunct;
 
     try {
-        // create a german locale
-        const std::locale loc (de_DE);
+        // try to contruct a german locale
+        const std::locale german (make_german_locale ());
 
         // obtain a numpunct facet for the german locale
-        const Numpunct &np = std::use_facet<Numpunct>(loc);
+        const Numpunct &np = std::use_facet<Numpunct>(german);
 
         std::cout <<   "German locale"
                   << "\nDecimal point       = " << np.decimal_point ()
@@ -64,7 +95,7 @@
     catch (std::runtime_error& e) {
         // a runtime_error will be thrown if the locale cannot be constructed
         std::cerr << "Caught runtime_error:\n"; 
-        std::cerr << e.what() << '\n';
+        std::cerr << e.what () << '\n';
     }
     catch (...) {
         std::cerr << "Caught an unknown exception\n"; 



Mime
View raw message