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 "subtitles_provider_csri.h"
|
||||
#include "text_file_writer.h"
|
||||
#include "video_context.h"
|
||||
|
||||
|
||||
|
@ -101,14 +102,14 @@ void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
|||
// Open from memory
|
||||
if (canOpenMem) {
|
||||
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);
|
||||
}
|
||||
|
||||
// Open from disk
|
||||
else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,8 @@ TextFileWriter::TextFileWriter(wxString const& filename, wxString encoding)
|
|||
}
|
||||
|
||||
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
|
||||
try {
|
||||
|
@ -88,8 +89,15 @@ TextFileWriter::~TextFileWriter() {
|
|||
void TextFileWriter::WriteLineToFile(wxString line, bool addLineBreak) {
|
||||
if (addLineBreak) line += L"\n";
|
||||
|
||||
std::string buf = conv->Convert(line.utf8_str().data());
|
||||
// On non-windows this cast does nothing
|
||||
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);
|
||||
};
|
||||
|
||||
#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