Commit f00214aa authored by Dāvis Mosāns's avatar Dāvis Mosāns Committed by Brad King

cmGeneratedFileStream: Add optional encoding support

This allows to save file stream in different encoding than internal
encoding.
parent bb1d3370
Pipeline #29542 passed with stage
......@@ -10,13 +10,21 @@
#include <cm_zlib.h>
#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<void>(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<void>(encoding);
#endif
}
cmGeneratedFileStream::~cmGeneratedFileStream()
......
......@@ -5,6 +5,7 @@
#include <cmConfigure.h>
#include <cm_codecvt.hxx>
#include <cmsys/FStream.hxx>
#include <string>
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment