From 67599c7ada47f37da950ca276538076be90eabb9 Mon Sep 17 00:00:00 2001 From: Ben McMorran Date: Fri, 31 Jul 2020 17:37:26 -0700 Subject: cmGeneratedFileStream: Add WriteRaw method --- Source/cmGeneratedFileStream.cxx | 14 +++++++++++++- Source/cmGeneratedFileStream.h | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 345f0ba..2768547 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -14,10 +14,11 @@ #endif cmGeneratedFileStream::cmGeneratedFileStream(Encoding encoding) + : OriginalLocale(getloc()) { #ifndef CMAKE_BOOTSTRAP if (encoding != codecvt::None) { - imbue(std::locale(getloc(), new codecvt(encoding))); + imbue(std::locale(OriginalLocale, new codecvt(encoding))); } #else static_cast(encoding); @@ -228,3 +229,14 @@ void cmGeneratedFileStream::SetTempExt(std::string const& ext) { this->TempExt = ext; } + +void cmGeneratedFileStream::WriteRaw(std::string const& data) +{ +#ifndef CMAKE_BOOTSTRAP + std::locale activeLocale = this->imbue(this->OriginalLocale); + this->write(data.data(), data.size()); + this->imbue(activeLocale); +#else + this->write(data.data(), data.size()); +#endif +} diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h index 3dee142..f6da86e 100644 --- a/Source/cmGeneratedFileStream.h +++ b/Source/cmGeneratedFileStream.h @@ -147,6 +147,16 @@ public: * This does not work if the file was opened by the constructor. */ void SetTempExt(std::string const& ext); + + /** + * Writes the given string directly to the file without changing the + * encoding. + */ + void WriteRaw(std::string const& data); + +private: + // The original locale of the stream (performs no encoding conversion). + std::locale OriginalLocale; }; #endif -- cgit v0.12