summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmGeneratedFileStream.cxx14
-rw-r--r--Source/cmGeneratedFileStream.h6
2 files changed, 20 insertions, 0 deletions
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx
index 6212bbd..215c3c2 100644
--- a/Source/cmGeneratedFileStream.cxx
+++ b/Source/cmGeneratedFileStream.cxx
@@ -239,6 +239,20 @@ void cmGeneratedFileStream::SetTempExt(std::string const& ext)
this->TempExt = ext;
}
+void cmGeneratedFileStream::WriteAltEncoding(std::string const& data,
+ Encoding encoding)
+{
+#ifndef CMAKE_BOOTSTRAP
+ std::locale prevLocale =
+ this->imbue(std::locale(this->getloc(), new codecvt(encoding)));
+ this->write(data.data(), data.size());
+ this->imbue(prevLocale);
+#else
+ static_cast<void>(encoding);
+ this->write(data.data(), data.size());
+#endif
+}
+
void cmGeneratedFileStream::WriteRaw(std::string const& data)
{
#ifndef CMAKE_BOOTSTRAP
diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h
index bb7e3bf..77fd7ef 100644
--- a/Source/cmGeneratedFileStream.h
+++ b/Source/cmGeneratedFileStream.h
@@ -148,6 +148,12 @@ public:
void SetTempExt(std::string const& ext);
/**
+ * Write a specific string using an alternate encoding.
+ * Afterward, the original encoding is restored.
+ */
+ void WriteAltEncoding(std::string const& data, Encoding encoding);
+
+ /**
* Writes the given string directly to the file without changing the
* encoding.
*/