forked from mia/Aegisub
Eliminate unnessesary character set conversions in TextFileWriter
Originally committed to SVN as r4579.
This commit is contained in:
parent
53fb43c7e6
commit
d1f36bdc43
3 changed files with 24 additions and 7 deletions
|
@ -44,6 +44,7 @@
|
||||||
|
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "subtitles_provider_csri.h"
|
#include "subtitles_provider_csri.h"
|
||||||
|
#include "text_file_writer.h"
|
||||||
#include "video_context.h"
|
#include "video_context.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,14 +102,14 @@ void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
||||||
// Open from memory
|
// Open from memory
|
||||||
if (canOpenMem) {
|
if (canOpenMem) {
|
||||||
std::vector<char> data;
|
std::vector<char> data;
|
||||||
subs->SaveMemory(data,_T("UTF-8"));
|
subs->SaveMemory(data,wxSTRING_ENCODING);
|
||||||
instance = csri_open_mem(renderer,&data[0],data.size(),NULL);
|
instance = csri_open_mem(renderer,&data[0],data.size(),NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open from disk
|
// Open from disk
|
||||||
else {
|
else {
|
||||||
wxString subsFileName = VideoContext::Get()->GetTempWorkFile();
|
wxString subsFileName = VideoContext::Get()->GetTempWorkFile();
|
||||||
subs->Save(subsFileName,false,false,_T("UTF-8"));
|
subs->Save(subsFileName,false,false,wxSTRING_ENCODING);
|
||||||
instance = csri_open_file(renderer,subsFileName.mb_str(wxConvUTF8),NULL);
|
instance = csri_open_file(renderer,subsFileName.mb_str(wxConvUTF8),NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,8 @@ TextFileWriter::TextFileWriter(wxString const& filename, wxString encoding)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoding.empty()) encoding = lagi_wxString(OPT_GET("App/Save Charset")->GetString());
|
if (encoding.empty()) encoding = lagi_wxString(OPT_GET("App/Save Charset")->GetString());
|
||||||
conv.reset(new agi::charset::IconvWrapper("utf-8", encoding.c_str(), true));
|
if (encoding.Lower() != wxSTRING_ENCODING)
|
||||||
|
conv.reset(new agi::charset::IconvWrapper(wxSTRING_ENCODING, encoding.c_str(), true));
|
||||||
|
|
||||||
// Write the BOM
|
// Write the BOM
|
||||||
try {
|
try {
|
||||||
|
@ -88,8 +89,15 @@ TextFileWriter::~TextFileWriter() {
|
||||||
void TextFileWriter::WriteLineToFile(wxString line, bool addLineBreak) {
|
void TextFileWriter::WriteLineToFile(wxString line, bool addLineBreak) {
|
||||||
if (addLineBreak) line += L"\n";
|
if (addLineBreak) line += L"\n";
|
||||||
|
|
||||||
std::string buf = conv->Convert(line.utf8_str().data());
|
// On non-windows this cast does nothing
|
||||||
file.write(buf.data(), buf.size());
|
const char *data = reinterpret_cast<const char *>(line.wx_str());
|
||||||
|
size_t len = line.size() * sizeof(wxStringCharType);
|
||||||
|
|
||||||
|
if (conv.get()) {
|
||||||
|
std::string buf = conv->Convert(std::string(data, len));
|
||||||
|
file.write(buf.data(), buf.size());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
file.write(data, len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -73,3 +73,11 @@ public:
|
||||||
|
|
||||||
void WriteLineToFile(wxString line, bool addLineBreak=true);
|
void WriteLineToFile(wxString line, bool addLineBreak=true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if wxUSE_UNICODE_UTF8
|
||||||
|
#define wxSTRING_ENCODING "utf-8"
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#define wxSTRING_ENCODING "utf-16le"
|
||||||
|
#else
|
||||||
|
#error wx must be built with wxUSE_UNICODE_UTF8
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue