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

View file

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

View file

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

View file

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