changeset 2334:dd26536454a0

fix for mingw
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 15 Jul 2017 13:13:00 +0200
parents 6677cdbfbafd
children 174c3616ab6d
files Core/Toolbox.cpp Resources/Configuration.json
diffstat 2 files changed, 54 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Sat Jul 15 11:06:59 2017 +0200
+++ b/Core/Toolbox.cpp	Sat Jul 15 13:13:00 2017 +0200
@@ -1255,42 +1255,73 @@
 
 
   static std::auto_ptr<std::locale>  globalLocale_;
+
+  static bool SetGlobalLocale(const char* locale)
+  {
+    globalLocale_.reset(NULL);
+
+    try
+    {
+      if (locale == NULL)
+      {
+        LOG(WARNING) << "Falling back to system-wide default locale";
+        globalLocale_.reset(new std::locale());
+      }
+      else
+      {
+        LOG(WARNING) << "Using locale: \"" << locale << "\"";
+        globalLocale_.reset(new std::locale(locale));
+      }
+    }
+    catch (std::runtime_error&)
+    {
+    }
+
+    return (globalLocale_.get() != NULL);
+  }
   
   void Toolbox::InitializeGlobalLocale(const char* locale)
   {
     // Make Orthanc use English, United States locale
-
-#if defined(_WIN32)
-    // For Windows: use default locale (one might use "en_US" instead)
+    // Linux: use "en_US.UTF-8"
+    // Windows: use ""
+    // Wine: use NULL
+    
+#if defined(__MINGW32__)
+    // Visibly, there is no support of locales in MinGW yet
+    // http://mingw.5.n7.nabble.com/How-to-use-std-locale-global-with-MinGW-correct-td33048.html
+    static const char* DEFAULT_LOCALE = NULL;
+#elif defined(_WIN32)
+    // For Windows: use default locale (using "en_US" does not work)
     static const char* DEFAULT_LOCALE = "";
 #else
     // For Linux & cie
     static const char* DEFAULT_LOCALE = "en_US.UTF-8";
 #endif
 
-    try
+    bool ok;
+    
+    if (locale == NULL)
     {
-      if (locale != NULL)
-      {
-        LOG(WARNING) << "Using user-specified locale: \"" << locale << "\"";
-        globalLocale_.reset(new std::locale(locale));
-      }
-      else if (DEFAULT_LOCALE == NULL)
-      {
-        LOG(WARNING) << "Using system-wide default locale";
-        globalLocale_.reset(new std::locale());
-      }
-      else
-      {
-        LOG(WARNING) << "Using default locale: \"" << DEFAULT_LOCALE << "\"";
-        globalLocale_.reset(new std::locale(DEFAULT_LOCALE));
-      }
+      ok = SetGlobalLocale(DEFAULT_LOCALE);
+
+#if defined(__MINGW32__)
+      LOG(WARNING) << "This is a MinGW build, case-insensitive comparison of "
+                   << "strings with accents will not work outside of Wine";
+#endif
     }
-    catch (std::runtime_error&)
+    else
+    {
+      ok = SetGlobalLocale(locale);
+    }
+
+    if (!ok &&
+        !SetGlobalLocale(NULL))
     {
       LOG(ERROR) << "Cannot initialize global locale";
       throw OrthancException(ErrorCode_InternalError);
     }
+
   }
 
 
--- a/Resources/Configuration.json	Sat Jul 15 11:06:59 2017 +0200
+++ b/Resources/Configuration.json	Sat Jul 15 13:13:00 2017 +0200
@@ -334,8 +334,9 @@
   // interest in the "Dictionary" configuration option below.
   "LoadPrivateDictionary" : true,
 
-  // Locale to be used by Orthanc. Notably used if comparing strings
-  // in a case-insensitive way.
+  // Locale to be used by Orthanc. Currently, only used if comparing
+  // strings in a case-insensitive way. It should be safe to keep this
+  // value undefined, which lets Orthanc autodetect the suitable locale.
   // "Locale" : "en_US.UTF-8",
 
   // Register a new tag in the dictionary of DICOM tags that are known