comparison Core/Toolbox.cpp @ 2334:dd26536454a0

fix for mingw
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 15 Jul 2017 13:13:00 +0200
parents 6677cdbfbafd
children 56504f89d4ac
comparison
equal deleted inserted replaced
2333:6677cdbfbafd 2334:dd26536454a0
1253 return IsUuid(str.substr(0, 36)); 1253 return IsUuid(str.substr(0, 36));
1254 } 1254 }
1255 1255
1256 1256
1257 static std::auto_ptr<std::locale> globalLocale_; 1257 static std::auto_ptr<std::locale> globalLocale_;
1258
1259 static bool SetGlobalLocale(const char* locale)
1260 {
1261 globalLocale_.reset(NULL);
1262
1263 try
1264 {
1265 if (locale == NULL)
1266 {
1267 LOG(WARNING) << "Falling back to system-wide default locale";
1268 globalLocale_.reset(new std::locale());
1269 }
1270 else
1271 {
1272 LOG(WARNING) << "Using locale: \"" << locale << "\"";
1273 globalLocale_.reset(new std::locale(locale));
1274 }
1275 }
1276 catch (std::runtime_error&)
1277 {
1278 }
1279
1280 return (globalLocale_.get() != NULL);
1281 }
1258 1282
1259 void Toolbox::InitializeGlobalLocale(const char* locale) 1283 void Toolbox::InitializeGlobalLocale(const char* locale)
1260 { 1284 {
1261 // Make Orthanc use English, United States locale 1285 // Make Orthanc use English, United States locale
1262 1286 // Linux: use "en_US.UTF-8"
1263 #if defined(_WIN32) 1287 // Windows: use ""
1264 // For Windows: use default locale (one might use "en_US" instead) 1288 // Wine: use NULL
1289
1290 #if defined(__MINGW32__)
1291 // Visibly, there is no support of locales in MinGW yet
1292 // http://mingw.5.n7.nabble.com/How-to-use-std-locale-global-with-MinGW-correct-td33048.html
1293 static const char* DEFAULT_LOCALE = NULL;
1294 #elif defined(_WIN32)
1295 // For Windows: use default locale (using "en_US" does not work)
1265 static const char* DEFAULT_LOCALE = ""; 1296 static const char* DEFAULT_LOCALE = "";
1266 #else 1297 #else
1267 // For Linux & cie 1298 // For Linux & cie
1268 static const char* DEFAULT_LOCALE = "en_US.UTF-8"; 1299 static const char* DEFAULT_LOCALE = "en_US.UTF-8";
1269 #endif 1300 #endif
1270 1301
1271 try 1302 bool ok;
1272 { 1303
1273 if (locale != NULL) 1304 if (locale == NULL)
1274 { 1305 {
1275 LOG(WARNING) << "Using user-specified locale: \"" << locale << "\""; 1306 ok = SetGlobalLocale(DEFAULT_LOCALE);
1276 globalLocale_.reset(new std::locale(locale)); 1307
1277 } 1308 #if defined(__MINGW32__)
1278 else if (DEFAULT_LOCALE == NULL) 1309 LOG(WARNING) << "This is a MinGW build, case-insensitive comparison of "
1279 { 1310 << "strings with accents will not work outside of Wine";
1280 LOG(WARNING) << "Using system-wide default locale"; 1311 #endif
1281 globalLocale_.reset(new std::locale()); 1312 }
1282 } 1313 else
1283 else 1314 {
1284 { 1315 ok = SetGlobalLocale(locale);
1285 LOG(WARNING) << "Using default locale: \"" << DEFAULT_LOCALE << "\""; 1316 }
1286 globalLocale_.reset(new std::locale(DEFAULT_LOCALE)); 1317
1287 } 1318 if (!ok &&
1288 } 1319 !SetGlobalLocale(NULL))
1289 catch (std::runtime_error&)
1290 { 1320 {
1291 LOG(ERROR) << "Cannot initialize global locale"; 1321 LOG(ERROR) << "Cannot initialize global locale";
1292 throw OrthancException(ErrorCode_InternalError); 1322 throw OrthancException(ErrorCode_InternalError);
1293 } 1323 }
1324
1294 } 1325 }
1295 1326
1296 1327
1297 void Toolbox::FinalizeGlobalLocale() 1328 void Toolbox::FinalizeGlobalLocale()
1298 { 1329 {