Consolidate all entries of each group when there are duplicate sections
Dealing with multiple instances of each section makes the code significantly more complicated, and in most cases Aegisub doesn't actually bother to handle it correctly.
This commit is contained in:
parent
b94547aa71
commit
49ed0551ad
2 changed files with 23 additions and 15 deletions
|
@ -51,7 +51,7 @@ void AssParser::ParseAttachmentLine(wxString const& data) {
|
||||||
// Data is over, add attachment to the file
|
// Data is over, add attachment to the file
|
||||||
if (!valid_data || is_filename) {
|
if (!valid_data || is_filename) {
|
||||||
attach->Finish();
|
attach->Finish();
|
||||||
target->Line.push_back(*attach.release());
|
InsertLine(attach.release());
|
||||||
AddLine(data);
|
AddLine(data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -60,7 +60,7 @@ void AssParser::ParseAttachmentLine(wxString const& data) {
|
||||||
// Done building
|
// Done building
|
||||||
if (data.Length() < 80) {
|
if (data.Length() < 80) {
|
||||||
attach->Finish();
|
attach->Finish();
|
||||||
target->Line.push_back(*attach.release());
|
InsertLine(attach.release());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,33 +87,27 @@ void AssParser::ParseScriptInfoLine(wxString const& data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
target->Line.push_back(*new AssEntry(data, "[Script Info]"));
|
InsertLine(new AssEntry(data, "[Script Info]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssParser::ParseEventLine(wxString const& data) {
|
void AssParser::ParseEventLine(wxString const& data) {
|
||||||
if (data.StartsWith("Dialogue:") || data.StartsWith("Comment:"))
|
if (data.StartsWith("Dialogue:") || data.StartsWith("Comment:"))
|
||||||
target->Line.push_back(*new AssDialogue(data));
|
InsertLine(new AssDialogue(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssParser::ParseStyleLine(wxString const& data) {
|
void AssParser::ParseStyleLine(wxString const& data) {
|
||||||
if (data.StartsWith("Style:"))
|
if (data.StartsWith("Style:"))
|
||||||
target->Line.push_back(*new AssStyle(data, version));
|
InsertLine(new AssStyle(data, version));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssParser::ParseFontLine(wxString const& data) {
|
void AssParser::ParseFontLine(wxString const& data) {
|
||||||
if (data.StartsWith("fontname: ")) {
|
if (data.StartsWith("fontname: "))
|
||||||
attach.reset(new AssAttachment(data.Mid(10), "[Fonts]"));
|
attach.reset(new AssAttachment(data.Mid(10), "[Fonts]"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssParser::ParseGraphicsLine(wxString const& data) {
|
void AssParser::ParseGraphicsLine(wxString const& data) {
|
||||||
if (data.StartsWith("filename: ")) {
|
if (data.StartsWith("filename: "))
|
||||||
attach.reset(new AssAttachment(data.Mid(10), "[Graphics]"));
|
attach.reset(new AssAttachment(data.Mid(10), "[Graphics]"));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssParser::AppendUnknownLine(wxString const& data) {
|
|
||||||
target->Line.push_back(*new AssEntry(data, target->Line.back().group));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssParser::AddLine(wxString const& data) {
|
void AssParser::AddLine(wxString const& data) {
|
||||||
|
@ -151,9 +145,18 @@ void AssParser::AddLine(wxString const& data) {
|
||||||
else if (low == "[fonts]")
|
else if (low == "[fonts]")
|
||||||
state = &AssParser::ParseFontLine;
|
state = &AssParser::ParseFontLine;
|
||||||
else
|
else
|
||||||
state = &AssParser::AppendUnknownLine;
|
state = &AssParser::UnknownLine;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
(this->*state)(data);
|
(this->*state)(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssParser::InsertLine(AssEntry *entry) {
|
||||||
|
auto it = insertion_positions.find(entry->group);
|
||||||
|
if (it == insertion_positions.end())
|
||||||
|
target->Line.push_back(*entry);
|
||||||
|
else
|
||||||
|
target->Line.insert(++target->Line.iterator_to(*it->second), *entry);
|
||||||
|
insertion_positions[entry->group] = entry;
|
||||||
|
}
|
||||||
|
|
|
@ -13,12 +13,14 @@
|
||||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class AssAttachment;
|
class AssAttachment;
|
||||||
|
class AssEntry;
|
||||||
class AssFile;
|
class AssFile;
|
||||||
|
|
||||||
class AssParser {
|
class AssParser {
|
||||||
|
@ -26,6 +28,9 @@ class AssParser {
|
||||||
int version;
|
int version;
|
||||||
std::unique_ptr<AssAttachment> attach;
|
std::unique_ptr<AssAttachment> attach;
|
||||||
void (AssParser::*state)(wxString const&);
|
void (AssParser::*state)(wxString const&);
|
||||||
|
std::map<wxString, AssEntry*> insertion_positions;
|
||||||
|
|
||||||
|
void InsertLine(AssEntry *entry);
|
||||||
|
|
||||||
void ParseAttachmentLine(wxString const& data);
|
void ParseAttachmentLine(wxString const& data);
|
||||||
void ParseEventLine(wxString const& data);
|
void ParseEventLine(wxString const& data);
|
||||||
|
@ -33,7 +38,7 @@ class AssParser {
|
||||||
void ParseScriptInfoLine(wxString const& data);
|
void ParseScriptInfoLine(wxString const& data);
|
||||||
void ParseFontLine(wxString const& data);
|
void ParseFontLine(wxString const& data);
|
||||||
void ParseGraphicsLine(wxString const& data);
|
void ParseGraphicsLine(wxString const& data);
|
||||||
void AppendUnknownLine(wxString const& data);
|
void UnknownLine(wxString const&) { }
|
||||||
public:
|
public:
|
||||||
AssParser(AssFile *target, int version);
|
AssParser(AssFile *target, int version);
|
||||||
~AssParser();
|
~AssParser();
|
||||||
|
|
Loading…
Reference in a new issue