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; const std::string file_name;
public: public:
Save(const std::string& file); Save(const std::string& file, bool binary = false);
~Save(); ~Save();
std::ofstream& Get(); 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; LOG_D("agi/io/save/file") << file;
const std::string pwd = util::DirName(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; LOG_D("agi/io/save/file") << file;
const std::string pwd = util::DirName(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 /// Windows support is added. The code in the destructor needs fixing
/// as well. /// as well.
// This will open to file.XXXX. (tempfile) // 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() { Save::~Save() {

View file

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