forked from mia/Aegisub
Make AssTime::ParseASS a constructor overload instead
Originally committed to SVN as r6468.
This commit is contained in:
parent
26b7970ed0
commit
fae7261bd0
5 changed files with 13 additions and 17 deletions
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue