mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-02 11:49:55 -06:00
cmGeneratedFileStream: Add WriteRaw method
This commit is contained in:
@@ -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<void>(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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user