From f00214aa4f8036951a926efd7dc3891d47abce49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C4=81vis=20Mos=C4=81ns?= Date: Wed, 5 Oct 2016 16:43:21 +0300 Subject: cmGeneratedFileStream: Add optional encoding support This allows to save file stream in different encoding than internal encoding. --- Source/cmGeneratedFileStream.cxx | 19 +++++++++++++++++-- Source/cmGeneratedFileStream.h | 7 +++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 02717a4..6cdb7f5 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -10,13 +10,21 @@ #include #endif -cmGeneratedFileStream::cmGeneratedFileStream() +cmGeneratedFileStream::cmGeneratedFileStream(Encoding encoding) : cmGeneratedFileStreamBase() , Stream() { +#ifdef CMAKE_BUILD_WITH_CMAKE + if (encoding != codecvt::None) { + imbue(std::locale(getloc(), new codecvt(encoding))); + } +#else + static_cast(encoding); +#endif } -cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet) +cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet, + Encoding encoding) : cmGeneratedFileStreamBase(name) , Stream(TempName.c_str()) { @@ -26,6 +34,13 @@ cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet) this->TempName.c_str()); cmSystemTools::ReportLastSystemError(""); } +#ifdef CMAKE_BUILD_WITH_CMAKE + if (encoding != codecvt::None) { + imbue(std::locale(getloc(), new codecvt(encoding))); + } +#else + static_cast(encoding); +#endif } cmGeneratedFileStream::~cmGeneratedFileStream() diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h index 515954c..a027b01 100644 --- a/Source/cmGeneratedFileStream.h +++ b/Source/cmGeneratedFileStream.h @@ -5,6 +5,7 @@ #include +#include #include #include @@ -71,12 +72,13 @@ class cmGeneratedFileStream : private cmGeneratedFileStreamBase, { public: typedef cmsys::ofstream Stream; + typedef codecvt::Encoding Encoding; /** * This constructor prepares a default stream. The open method must * be used before writing to the stream. */ - cmGeneratedFileStream(); + cmGeneratedFileStream(Encoding encoding = codecvt::None); /** * This constructor takes the name of the file to be generated. It @@ -84,7 +86,8 @@ public: * file cannot be opened an error message is produced unless the * second argument is set to true. */ - cmGeneratedFileStream(const char* name, bool quiet = false); + cmGeneratedFileStream(const char* name, bool quiet = false, + Encoding encoding = codecvt::None); /** * The destructor checks the stream status to be sure the temporary -- cgit v0.12