From fae7261bd089aa72f26e8fa4630d759fe8d4d334 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 14 Feb 2012 00:35:06 +0000 Subject: [PATCH] Make AssTime::ParseASS a constructor overload instead Originally committed to SVN as r6468. --- aegisub/src/ass_dialogue.cpp | 4 ++-- aegisub/src/ass_time.cpp | 13 ++++++------- aegisub/src/ass_time.h | 3 +-- aegisub/src/subtitle_format_ttxt.cpp | 3 +-- aegisub/src/timeedit_ctrl.cpp | 7 +++---- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/aegisub/src/ass_dialogue.cpp b/aegisub/src/ass_dialogue.cpp index e51f9c064..cc699fb68 100644 --- a/aegisub/src/ass_dialogue.cpp +++ b/aegisub/src/ass_dialogue.cpp @@ -140,11 +140,11 @@ bool AssDialogue::Parse(wxString rawData, int version) { // Get start time if (!tkn.HasMoreTokens()) return false; - Start.ParseASS(tkn.GetNextToken()); + Start = tkn.GetNextToken(); // Get end time if (!tkn.HasMoreTokens()) return false; - End.ParseASS(tkn.GetNextToken()); + End = tkn.GetNextToken(); // Get style if (!tkn.HasMoreTokens()) return false; diff --git a/aegisub/src/ass_time.cpp b/aegisub/src/ass_time.cpp index 4c581fd0d..a1676a132 100644 --- a/aegisub/src/ass_time.cpp +++ b/aegisub/src/ass_time.cpp @@ -47,8 +47,9 @@ AssTime::AssTime(int time) : time(mid(0, time, 10 * 60 * 60 * 1000 - 1)) { } -void AssTime::ParseASS(wxString const& text) { - int ms = 0; +AssTime::AssTime(wxString const& text) +: time(0) +{ size_t pos = 0, end = 0; int colons = text.Freq(':'); @@ -59,20 +60,18 @@ void AssTime::ParseASS(wxString const& text) { // Hours if (colons == 2) { while (text[end++] != ':') { } - ms += AegiStringToInt(text, pos, end) * 60 * 60 * 1000; + time += AegiStringToInt(text, pos, end) * 60 * 60 * 1000; pos = end; } // Minutes if (colons >= 1) { while (text[end++] != ':') { } - ms += AegiStringToInt(text, pos, end) * 60 * 1000; + time += AegiStringToInt(text, pos, end) * 60 * 1000; } // Milliseconds (includes seconds) - ms += AegiStringToFix(text, 3, end, text.size()); - - *this = AssTime(ms); + time += AegiStringToFix(text, 3, end, text.size()); } wxString AssTime::GetASSFormated(bool msPrecision) const { diff --git a/aegisub/src/ass_time.h b/aegisub/src/ass_time.h index 6320efac3..0de545cc6 100644 --- a/aegisub/src/ass_time.h +++ b/aegisub/src/ass_time.h @@ -53,6 +53,7 @@ class AssTime { public: AssTime(int ms = 0); + AssTime(wxString const& text); /// Get millisecond, rounded to centisecond precision operator int() const { return time / 10 * 10; } @@ -63,8 +64,6 @@ public: int GetTimeMiliseconds() const; ///< Get the miliseconds portion of this time int GetTimeCentiseconds() const; ///< Get the centiseconds portion of this time - /// Parse an ASS time string, leaving the time unchanged if the string is malformed - void ParseASS(wxString const& text); /// Return the time as a string /// @param ms Use milliseconds precision, for non-ASS formats wxString GetASSFormated(bool ms=false) const; diff --git a/aegisub/src/subtitle_format_ttxt.cpp b/aegisub/src/subtitle_format_ttxt.cpp index 1b2757089..5e3404456 100644 --- a/aegisub/src/subtitle_format_ttxt.cpp +++ b/aegisub/src/subtitle_format_ttxt.cpp @@ -110,8 +110,7 @@ void TTXTSubtitleFormat::ReadFile(AssFile *target, wxString const& filename, wxS AssDialogue *TTXTSubtitleFormat::ProcessLine(wxXmlNode *node, AssDialogue *prev, int version) const { // Get time wxString sampleTime = node->GetAttribute("sampleTime", "00:00:00.000"); - AssTime time; - time.ParseASS(sampleTime); + AssTime time(sampleTime); // Set end time of last line if (prev) diff --git a/aegisub/src/timeedit_ctrl.cpp b/aegisub/src/timeedit_ctrl.cpp index 896e222f4..22b48eed4 100644 --- a/aegisub/src/timeedit_ctrl.cpp +++ b/aegisub/src/timeedit_ctrl.cpp @@ -128,7 +128,7 @@ void TimeEdit::OnModified(wxCommandEvent &event) { time = c->videoController->TimeAtFrame(temp, isEnd ? agi::vfr::END : agi::vfr::START); } else if (insert) - time.ParseASS(GetValue()); + time = GetValue(); } @@ -188,7 +188,7 @@ void TimeEdit::OnKeyDown(wxKeyEvent &event) { } // Overwrite the digit - time.ParseASS(text.Left(start) + (char)key + text.Mid(start + 1)); + time = text.Left(start) + (char)key + text.Mid(start + 1); SetValue(time.GetASSFormated()); SetInsertionPoint(start + 1); } @@ -238,8 +238,7 @@ void TimeEdit::PasteTime() { } wxTheClipboard->Close(); - AssTime tempTime; - tempTime.ParseASS(text); + AssTime tempTime(text); if (tempTime.GetASSFormated() == text) { SetTime(tempTime); SetSelection(0, GetValue().size());