Parse {} as an empty override block rather than an empty comment

Originally committed to SVN as r6164.
This commit is contained in:
Thomas Goyne 2011-12-26 22:21:02 +00:00
parent 04990e8694
commit 7b4759cc13
2 changed files with 24 additions and 30 deletions

View file

@ -240,37 +240,42 @@ wxString AssDialogue::GetSSAText () const {
return GetData(true); return GetData(true);
} }
void AssDialogue::ParseASSTags () { void AssDialogue::ParseASSTags() {
ClearBlocks(); ClearBlocks();
// Empty line, make an empty block
if (Text.empty()) {
Blocks.push_back(new AssDialogueBlockPlain);
return;
}
int drawingLevel = 0; int drawingLevel = 0;
const size_t len = Text.size(); for (size_t len = Text.size(), cur = 0; cur < len; ) {
size_t cur = 0;
size_t end = 0;
while (cur < len) {
// Overrides block // Overrides block
if (Text[cur] == '{') { if (Text[cur] == '{') {
++cur;
// Get contents of block // Get contents of block
wxString work; wxString work;
end = Text.find("}",cur); size_t end = Text.find("}", cur);
if (end == wxString::npos) { if (end == wxString::npos) {
work = Text.substr(cur); work = Text.substr(cur);
end = len; cur = len;
}
else {
work = Text.substr(cur, end - cur);
cur = end + 1;
} }
else work = Text.substr(cur,end-cur+1);
if (work.Find("\\") == wxNOT_FOUND) { if (work.size() && work.Find("\\") == wxNOT_FOUND) {
//We've found an override block with no backslashes //We've found an override block with no backslashes
//We're going to assume it's a comment and not consider it an override block //We're going to assume it's a comment and not consider it an override block
//Currently we'll treat this as a plain text block, but feel free to create a new class //Currently we'll treat this as a plain text block, but feel free to create a new class
AssDialogueBlockPlain *block = new AssDialogueBlockPlain; AssDialogueBlockPlain *block = new AssDialogueBlockPlain;
block->text = work; block->text = "{" + work + "}";
Blocks.push_back(block); Blocks.push_back(block);
} }
else { else {
work = work.substr(1,work.Len()-2); // trim { and }
// Create block // Create block
AssDialogueBlockOverride *block = new AssDialogueBlockOverride; AssDialogueBlockOverride *block = new AssDialogueBlockOverride;
block->parent = this; block->parent = this;
@ -286,20 +291,19 @@ void AssDialogue::ParseASSTags () {
} }
} }
} }
// Increase
cur = end+1;
} }
// Plain-text/drawing block // Plain-text/drawing block
else { else {
wxString work; wxString work;
end = Text.find("{",cur); size_t end = Text.find("{",cur);
if (end == wxString::npos) { if (end == wxString::npos) {
work = Text.substr(cur); work = Text.substr(cur);
end = len; cur = len;
}
else {
work = Text.substr(cur, end - cur);
cur = end;
} }
else work = Text.substr(cur,end-cur);
// Plain-text // Plain-text
if (drawingLevel == 0) { if (drawingLevel == 0) {
@ -307,7 +311,6 @@ void AssDialogue::ParseASSTags () {
block->text = work; block->text = work;
Blocks.push_back(block); Blocks.push_back(block);
} }
// Drawing // Drawing
else { else {
AssDialogueBlockDrawing *block = new AssDialogueBlockDrawing; AssDialogueBlockDrawing *block = new AssDialogueBlockDrawing;
@ -315,17 +318,8 @@ void AssDialogue::ParseASSTags () {
block->Scale = drawingLevel; block->Scale = drawingLevel;
Blocks.push_back(block); Blocks.push_back(block);
} }
cur = end;
} }
} }
// Empty line, make an empty block
if (len == 0) {
AssDialogueBlockPlain *block = new AssDialogueBlockPlain;
block->text = "";
Blocks.push_back(block);
}
} }
void AssDialogue::StripTags () { void AssDialogue::StripTags () {

View file

@ -74,7 +74,7 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split) {
if (dynamic_cast<AssDialogueBlockPlain*>(block)) { if (dynamic_cast<AssDialogueBlockPlain*>(block)) {
// treat comments as overrides rather than dialogue // treat comments as overrides rather than dialogue
if (block->text.size() >= 2 && block->text[0] == '{') if (block->text[0] == '{')
syl.ovr_tags[syl.text.size()] += block->text; syl.ovr_tags[syl.text.size()] += block->text;
else else
syl.text += block->text; syl.text += block->text;