Fix writing of newlines on windows in charsets wider than one byte

Originally committed to SVN as r4786.
This commit is contained in:
Thomas Goyne 2010-09-15 05:00:12 +00:00
parent 84b8877d1d
commit fd5c1ecffc
4 changed files with 9 additions and 5 deletions

View File

@ -47,7 +47,7 @@ class Save {
const std::string file_name;
public:
Save(const std::string& file);
Save(const std::string& file, bool binary = false);
~Save();
std::ofstream& Get();
};

View File

@ -47,7 +47,7 @@ std::ifstream* Open(const std::string &file) {
}
Save::Save(const std::string& file): file_name(file) {
Save::Save(const std::string& file, bool binary): file_name(file) {
LOG_D("agi/io/save/file") << file;
const std::string pwd = util::DirName(file);

View File

@ -52,7 +52,7 @@ std::ifstream* Open(const std::string &file) {
}
Save::Save(const std::string& file): file_name(file) {
Save::Save(const std::string& file, bool binary): file_name(file) {
LOG_D("agi/io/save/file") << file;
const std::string pwd = util::DirName(file);
@ -71,7 +71,7 @@ Save::Save(const std::string& file): file_name(file) {
/// Windows support is added. The code in the destructor needs fixing
/// as well.
// This will open to file.XXXX. (tempfile)
fp = new std::ofstream(ConvertW(file + "_tmp").c_str());
fp = new std::ofstream(ConvertW(file + "_tmp").c_str(), binary ? std::ios::binary : std::ios::out);
}
Save::~Save() {

View File

@ -53,7 +53,7 @@
/// @param encoding
///
TextFileWriter::TextFileWriter(wxString const& filename, wxString encoding)
: file(new agi::io::Save(STD_STR(filename)))
: file(new agi::io::Save(STD_STR(filename), true))
, conv() {
if (encoding.empty()) encoding = lagi_wxString(OPT_GET("App/Save Charset")->GetString());
if (encoding.Lower() != wxSTRING_ENCODING)
@ -80,7 +80,11 @@ TextFileWriter::~TextFileWriter() {
/// @param line
/// @param addLineBreak
void TextFileWriter::WriteLineToFile(wxString line, bool addLineBreak) {
#ifdef _WIN32
if (addLineBreak) line += L"\r\n";
#else
if (addLineBreak) line += L"\n";
#endif
// On non-windows this cast does nothing
const char *data = reinterpret_cast<const char *>(line.wx_str());