forked from mia/Aegisub
Make Assfile::SetScriptInfo slightly less slow
Originally committed to SVN as r5569.
This commit is contained in:
parent
e12bcc6aef
commit
ccf9f64818
2 changed files with 21 additions and 38 deletions
|
@ -632,51 +632,34 @@ int AssFile::GetScriptInfoAsInt(const wxString key) {
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
|
void AssFile::SetScriptInfo(wxString const& key, wxString const& value) {
|
||||||
wxString key = _key;;
|
wxString search_key = key.Lower() + ":";
|
||||||
key.Lower();
|
size_t key_size = search_key.size();
|
||||||
key += _T(":");
|
std::list<AssEntry*>::iterator script_info_end;
|
||||||
std::list<AssEntry*>::iterator cur;
|
bool found_script_info = false;
|
||||||
std::list<AssEntry*>::iterator prev;
|
|
||||||
bool GotIn = false;
|
|
||||||
|
|
||||||
// Look for it
|
for (std::list<AssEntry*>::iterator cur = Line.begin(); cur != Line.end(); ++cur) {
|
||||||
for (cur=Line.begin();cur!=Line.end();cur++) {
|
|
||||||
if ((*cur)->group == _T("[Script Info]")) {
|
if ((*cur)->group == _T("[Script Info]")) {
|
||||||
GotIn = true;
|
found_script_info = true;
|
||||||
wxString curText = (*cur)->GetEntryData();
|
wxString cur_text = (*cur)->GetEntryData().Left(key_size).Lower();
|
||||||
curText.Lower();
|
|
||||||
|
|
||||||
// Found
|
if (cur_text == search_key) {
|
||||||
if (curText.StartsWith(key)) {
|
if (value.empty()) {
|
||||||
// Set value
|
delete *cur;
|
||||||
if (value != "") {
|
|
||||||
wxString result = _key;
|
|
||||||
result += _T(": ");
|
|
||||||
result += value;
|
|
||||||
(*cur)->SetEntryData(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove key
|
|
||||||
else {
|
|
||||||
Line.erase(cur);
|
Line.erase(cur);
|
||||||
return;
|
}
|
||||||
|
else {
|
||||||
|
(*cur)->SetEntryData(key + ": " + value);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
script_info_end = cur;
|
||||||
if (!(*cur)->GetEntryData().empty()) prev = cur;
|
|
||||||
}
|
}
|
||||||
|
else if (found_script_info) {
|
||||||
// Add
|
if (value.size()) {
|
||||||
else if (GotIn) {
|
AssEntry *entry = new AssEntry(key + ": " + value);
|
||||||
if (value != "") {
|
entry->group = "[Script Info]";
|
||||||
wxString result = _key;
|
Line.insert(script_info_end, entry);
|
||||||
result += _T(": ");
|
|
||||||
result += value;
|
|
||||||
AssEntry *entry = new AssEntry(result);
|
|
||||||
entry->group = (*prev)->group;
|
|
||||||
Line.insert(++prev,entry);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ public:
|
||||||
/// Get the value in a [Script Info] key as string.
|
/// Get the value in a [Script Info] key as string.
|
||||||
wxString GetScriptInfo(const wxString key);
|
wxString GetScriptInfo(const wxString key);
|
||||||
/// Set the value of a [Script Info] key. Adds it if it doesn't exist.
|
/// Set the value of a [Script Info] key. Adds it if it doesn't exist.
|
||||||
void SetScriptInfo(const wxString key,const wxString value);
|
void SetScriptInfo(wxString key, wxString const& value);
|
||||||
// Add a ";" comment in the [Script Info] section
|
// Add a ";" comment in the [Script Info] section
|
||||||
void AddComment(const wxString comment);
|
void AddComment(const wxString comment);
|
||||||
/// @brief Add a line to the file
|
/// @brief Add a line to the file
|
||||||
|
|
Loading…
Reference in a new issue