diff options
author | Nils Gladitz <nilsgladitz@gmail.com> | 2015-04-09 18:56:43 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-04-13 12:59:34 (GMT) |
commit | a198839a7b110a47d76d47e342b1c63f908e6878 (patch) | |
tree | 64a03ec951d59b32d9ba4c6243a5bf072505cb20 /Source/cmCLocaleEnvironmentScope.cxx | |
parent | 48040c19d5f1bcec55a130fcf8f8d83db27291b4 (diff) | |
download | CMake-a198839a7b110a47d76d47e342b1c63f908e6878.zip CMake-a198839a7b110a47d76d47e342b1c63f908e6878.tar.gz CMake-a198839a7b110a47d76d47e342b1c63f908e6878.tar.bz2 |
CTest: Fix locale used for VCS updates
6a661f06030b85b4484733375bbb0aa23eca7446 fixed the
locale used for message output but at the same time broke the locale
used for filename encodings.
This commit preserves LC_CTYPE in the presence of LC_ALL.
Diffstat (limited to 'Source/cmCLocaleEnvironmentScope.cxx')
-rw-r--r-- | Source/cmCLocaleEnvironmentScope.cxx | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Source/cmCLocaleEnvironmentScope.cxx b/Source/cmCLocaleEnvironmentScope.cxx new file mode 100644 index 0000000..5792302 --- /dev/null +++ b/Source/cmCLocaleEnvironmentScope.cxx @@ -0,0 +1,67 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2015 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#include "cmCLocaleEnvironmentScope.h" + +#include "cmSystemTools.h" + +#include <sstream> + +cmCLocaleEnvironmentScope::cmCLocaleEnvironmentScope() +{ + this->SetEnv("LANGUAGE", ""); + this->SetEnv("LC_MESSAGES", "C"); + + std::string lcAll = this->GetEnv("LC_ALL"); + + if(!lcAll.empty()) + { + this->SetEnv("LC_ALL", ""); + this->SetEnv("LC_CTYPE", lcAll); + } +} + +std::string cmCLocaleEnvironmentScope::GetEnv(std::string const& key) +{ + const char* value = cmSystemTools::GetEnv(key); + return value ? value : std::string(); +} + +void cmCLocaleEnvironmentScope::SetEnv( + std::string const& key, std::string const& value) +{ + std::string oldValue = this->GetEnv(key); + + this->EnvironmentBackup.insert(std::make_pair(key, oldValue)); + + if(value.empty()) + { + cmSystemTools::UnsetEnv(key.c_str()); + } + else + { + std::stringstream tmp; + tmp << key << "=" << value; + cmSystemTools::PutEnv(tmp.str()); + } +} + +cmCLocaleEnvironmentScope::~cmCLocaleEnvironmentScope() +{ + for(backup_map_t::const_iterator i = this->EnvironmentBackup.begin(); + i != this->EnvironmentBackup.end(); ++i) + { + std::stringstream tmp; + tmp << i->first << "=" << i->second; + cmSystemTools::PutEnv(tmp.str()); + } +} |