CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmCLocaleEnvironmentScope.cxx
blobc6c38f83cfc364c1db891ffb79a6254c5bf4b9e9
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmCLocaleEnvironmentScope.h"
5 #include <sstream>
6 #include <utility>
8 #include "cmSystemTools.h"
10 cmCLocaleEnvironmentScope::cmCLocaleEnvironmentScope()
12 this->SetEnv("LANGUAGE", "");
13 this->SetEnv("LC_MESSAGES", "C");
15 std::string lcAll = this->GetEnv("LC_ALL");
17 if (!lcAll.empty()) {
18 this->SetEnv("LC_ALL", "");
19 this->SetEnv("LC_CTYPE", lcAll);
23 std::string cmCLocaleEnvironmentScope::GetEnv(std::string const& key)
25 std::string value;
26 cmSystemTools::GetEnv(key, value);
27 return value;
30 void cmCLocaleEnvironmentScope::SetEnv(std::string const& key,
31 std::string const& value)
33 std::string oldValue = this->GetEnv(key);
35 this->EnvironmentBackup.insert(std::make_pair(key, oldValue));
37 if (value.empty()) {
38 cmSystemTools::UnsetEnv(key.c_str());
39 } else {
40 std::ostringstream tmp;
41 tmp << key << "=" << value;
42 cmSystemTools::PutEnv(tmp.str());
46 cmCLocaleEnvironmentScope::~cmCLocaleEnvironmentScope()
48 for (auto const& envb : this->EnvironmentBackup) {
49 std::ostringstream tmp;
50 tmp << envb.first << "=" << envb.second;
51 cmSystemTools::PutEnv(tmp.str());