Much faster subtitles loading (only really relevant for huge files, though) and undo stack operations.

Originally committed to SVN as r1097.
This commit is contained in:
Rodrigo Braz Monteiro 2007-04-19 15:22:47 +00:00
parent 95bc4227f2
commit 877c4bf1b1
4 changed files with 65 additions and 47 deletions

View file

@ -252,11 +252,11 @@ bool AssDialogue::Parse(wxString rawData, int version) {
// Make data
wxString AssDialogue::MakeData() {
// Prepare
wxString final = _T("");
static wxString final = _T("");
// Write all final
if (Comment) final += _T("Comment: ");
else final += _T("Dialogue: ");
if (Comment) final = _T("Comment: ");
else final = _T("Dialogue: ");
final += wxString::Format(_T("%01i"),Layer);
final += _T(",");
@ -279,6 +279,12 @@ wxString AssDialogue::MakeData() {
Effect.Replace(_T(","),_T(";"));
final += Effect + _T(",");
final += Text;
// Make sure that final has no line breaks
final.Replace(_T("\n"),_T(""));
final.Replace(_T("\r"),_T(""));
// Return final
return final;
}
@ -824,7 +830,7 @@ AssEntry *AssDialogue::Clone() {
final->StartMS = final->StartMS;
final->Style = Style;
final->Text = Text;
final->SetEntryData(GetEntryData());
//final->SetEntryData(GetEntryData());
// Return
return final;

View file

@ -67,20 +67,19 @@ void AssTime::ParseASS (const wxString _text) {
try {
// Hours
end = text.find(_T(":"),pos);
temp = text.SubString(pos,end-1);
end = text.Find(_T(':'));
temp = text.Left(end);
if (!temp.ToLong(&th)) throw 0;
pos = end+1;
text[end] = _T(' ');
// Minutes
end = text.find(_T(":"),pos);
temp = text.SubString(pos,end-1);
end = text.Find(_T(':'));
temp = text.Mid(pos,end-pos);
if (!temp.ToLong(&tm)) throw 0;
pos = end+1;
// Seconds
end = text.length();
temp = text.Mid(pos);
temp = text.Mid(end+1);
if (!temp.ToDouble(&ts_raw)) throw 0;
// Split into seconds and fraction

View file

@ -95,27 +95,30 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
wxbuffer = file.ReadLineFromFile();
// Convert v4 styles to v4+ styles
// Ugly hacks to allow intermixed v4 and v4+ style sections
if (wxbuffer.Lower() == _T("[v4 styles]")) {
wxbuffer = _T("[V4+ Styles]");
curgroup = wxbuffer;
version = 0;
}
else if (wxbuffer.Lower() == _T("[v4+ styles]")) {
curgroup = wxbuffer;
version = 1;
}
else if (wxbuffer.Lower() == _T("[v4++ styles]")) {
wxbuffer = _T("[V4+ Styles]");
curgroup = wxbuffer;
version = 2;
}
// Not-so-special case for other groups, just set it
else if (!wxbuffer.IsEmpty() && wxbuffer[0] == _T('[')) {
curgroup = wxbuffer;
// default from extension in all other sections
//version = 1;
//if (filename.Right(4).Lower() == _T(".ssa")) version = 0;
if (!wxbuffer.IsEmpty() && wxbuffer[0] == _T('[')) {
// Ugly hacks to allow intermixed v4 and v4+ style sections
wxString low = wxbuffer.Lower();
if (low == _T("[v4 styles]")) {
wxbuffer = _T("[V4+ Styles]");
curgroup = wxbuffer;
version = 0;
}
else if (low == _T("[v4+ styles]")) {
curgroup = wxbuffer;
version = 1;
}
else if (low == _T("[v4++ styles]")) {
wxbuffer = _T("[V4+ Styles]");
curgroup = wxbuffer;
version = 2;
}
// Not-so-special case for other groups, just set it
else {
curgroup = wxbuffer;
// default from extension in all other sections
//version = 1;
//if (filename.Right(4).Lower() == _T(".ssa")) version = 0;
}
}
// Add line

View file

@ -184,7 +184,15 @@ void TextFileReader::SetEncodingConfiguration() {
// Reads a line from file
wxString TextFileReader::ReadLineFromFile() {
Open();
wxString wxbuffer = _T("");
wxString wxbuffer;
int bufAlloc = 1024;
wxbuffer.Alloc(bufAlloc);
#ifdef TEXT_READER_USE_STDIO
char buffer[512];
buffer[0] = 0;
#else
std::string buffer = "";
#endif
// Read UTF-16 line from file
if (Is16) {
@ -212,6 +220,10 @@ wxString TextFileReader::ReadLineFromFile() {
// Convert two chars into a widechar and append to string
ch = *((wchar_t*)charbuffer);
if (wxbuffer.Length() == bufAlloc) {
bufAlloc *= 2;
wxbuffer.Alloc(bufAlloc);
}
wxbuffer += ch;
n++;
}
@ -220,7 +232,6 @@ wxString TextFileReader::ReadLineFromFile() {
// Read ASCII/UTF-8 line from file
else {
#ifdef TEXT_READER_USE_STDIO
char buffer[512];
while (1) {
buffer[511] = '\1';
if (fgets(buffer, 512, file)) {
@ -240,31 +251,30 @@ wxString TextFileReader::ReadLineFromFile() {
}
}
#else
std::string buffer;
getline(file,buffer);
wxString lineresult(buffer.c_str(),*conv);
wxbuffer = lineresult;
wxbuffer = wxString(buffer.c_str(),*conv);
#endif
}
// Remove line breaks
wxbuffer.Replace(_T("\r"),_T(""));
wxbuffer.Replace(_T("\n"),_T(""));
// Final string
wxString final = wxString(wxbuffer);
//wxbuffer.Replace(_T("\r"),_T("\0"));
//wxbuffer.Replace(_T("\n"),_T("\0"));
size_t len=wxbuffer.Length();
for (size_t i=0;i<len;i++) {
if (wxbuffer[i] == _T('\r') || wxbuffer[i] == _T('\n')) wxbuffer[i] = _T(' ');
}
// Remove BOM
if (final.length() > 0 && final[0] == 0xFEFF) {
final = final.Mid(1);
if (wxbuffer.Length() > 0 && wxbuffer[0] == 0xFEFF) {
wxbuffer = wxbuffer.Mid(1);
}
// Trim
if (trim) {
final.Trim(true);
final.Trim(false);
wxbuffer.Trim(true);
wxbuffer.Trim(false);
}
return final;
return wxbuffer;
}