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
|
// Get start time
|
||||||
if (!tkn.HasMoreTokens()) return false;
|
if (!tkn.HasMoreTokens()) return false;
|
||||||
Start.ParseASS(tkn.GetNextToken());
|
Start = tkn.GetNextToken();
|
||||||
|
|
||||||
// Get end time
|
// Get end time
|
||||||
if (!tkn.HasMoreTokens()) return false;
|
if (!tkn.HasMoreTokens()) return false;
|
||||||
End.ParseASS(tkn.GetNextToken());
|
End = tkn.GetNextToken();
|
||||||
|
|
||||||
// Get style
|
// Get style
|
||||||
if (!tkn.HasMoreTokens()) return false;
|
if (!tkn.HasMoreTokens()) return false;
|
||||||
|
|
|
@ -47,8 +47,9 @@
|
||||||
|
|
||||||
AssTime::AssTime(int time) : time(mid(0, time, 10 * 60 * 60 * 1000 - 1)) { }
|
AssTime::AssTime(int time) : time(mid(0, time, 10 * 60 * 60 * 1000 - 1)) { }
|
||||||
|
|
||||||
void AssTime::ParseASS(wxString const& text) {
|
AssTime::AssTime(wxString const& text)
|
||||||
int ms = 0;
|
: time(0)
|
||||||
|
{
|
||||||
size_t pos = 0, end = 0;
|
size_t pos = 0, end = 0;
|
||||||
|
|
||||||
int colons = text.Freq(':');
|
int colons = text.Freq(':');
|
||||||
|
@ -59,20 +60,18 @@ void AssTime::ParseASS(wxString const& text) {
|
||||||
// Hours
|
// Hours
|
||||||
if (colons == 2) {
|
if (colons == 2) {
|
||||||
while (text[end++] != ':') { }
|
while (text[end++] != ':') { }
|
||||||
ms += AegiStringToInt(text, pos, end) * 60 * 60 * 1000;
|
time += AegiStringToInt(text, pos, end) * 60 * 60 * 1000;
|
||||||
pos = end;
|
pos = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Minutes
|
// Minutes
|
||||||
if (colons >= 1) {
|
if (colons >= 1) {
|
||||||
while (text[end++] != ':') { }
|
while (text[end++] != ':') { }
|
||||||
ms += AegiStringToInt(text, pos, end) * 60 * 1000;
|
time += AegiStringToInt(text, pos, end) * 60 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Milliseconds (includes seconds)
|
// Milliseconds (includes seconds)
|
||||||
ms += AegiStringToFix(text, 3, end, text.size());
|
time += AegiStringToFix(text, 3, end, text.size());
|
||||||
|
|
||||||
*this = AssTime(ms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString AssTime::GetASSFormated(bool msPrecision) const {
|
wxString AssTime::GetASSFormated(bool msPrecision) const {
|
||||||
|
|
|
@ -53,6 +53,7 @@ class AssTime {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AssTime(int ms = 0);
|
AssTime(int ms = 0);
|
||||||
|
AssTime(wxString const& text);
|
||||||
|
|
||||||
/// Get millisecond, rounded to centisecond precision
|
/// Get millisecond, rounded to centisecond precision
|
||||||
operator int() const { return time / 10 * 10; }
|
operator int() const { return time / 10 * 10; }
|
||||||
|
@ -63,8 +64,6 @@ public:
|
||||||
int GetTimeMiliseconds() const; ///< Get the miliseconds portion of this time
|
int GetTimeMiliseconds() const; ///< Get the miliseconds portion of this time
|
||||||
int GetTimeCentiseconds() const; ///< Get the centiseconds 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
|
/// Return the time as a string
|
||||||
/// @param ms Use milliseconds precision, for non-ASS formats
|
/// @param ms Use milliseconds precision, for non-ASS formats
|
||||||
wxString GetASSFormated(bool ms=false) const;
|
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 {
|
AssDialogue *TTXTSubtitleFormat::ProcessLine(wxXmlNode *node, AssDialogue *prev, int version) const {
|
||||||
// Get time
|
// Get time
|
||||||
wxString sampleTime = node->GetAttribute("sampleTime", "00:00:00.000");
|
wxString sampleTime = node->GetAttribute("sampleTime", "00:00:00.000");
|
||||||
AssTime time;
|
AssTime time(sampleTime);
|
||||||
time.ParseASS(sampleTime);
|
|
||||||
|
|
||||||
// Set end time of last line
|
// Set end time of last line
|
||||||
if (prev)
|
if (prev)
|
||||||
|
|
|
@ -128,7 +128,7 @@ void TimeEdit::OnModified(wxCommandEvent &event) {
|
||||||
time = c->videoController->TimeAtFrame(temp, isEnd ? agi::vfr::END : agi::vfr::START);
|
time = c->videoController->TimeAtFrame(temp, isEnd ? agi::vfr::END : agi::vfr::START);
|
||||||
}
|
}
|
||||||
else if (insert)
|
else if (insert)
|
||||||
time.ParseASS(GetValue());
|
time = GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ void TimeEdit::OnKeyDown(wxKeyEvent &event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite the digit
|
// 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());
|
SetValue(time.GetASSFormated());
|
||||||
SetInsertionPoint(start + 1);
|
SetInsertionPoint(start + 1);
|
||||||
}
|
}
|
||||||
|
@ -238,8 +238,7 @@ void TimeEdit::PasteTime() {
|
||||||
}
|
}
|
||||||
wxTheClipboard->Close();
|
wxTheClipboard->Close();
|
||||||
|
|
||||||
AssTime tempTime;
|
AssTime tempTime(text);
|
||||||
tempTime.ParseASS(text);
|
|
||||||
if (tempTime.GetASSFormated() == text) {
|
if (tempTime.GetASSFormated() == text) {
|
||||||
SetTime(tempTime);
|
SetTime(tempTime);
|
||||||
SetSelection(0, GetValue().size());
|
SetSelection(0, GetValue().size());
|
||||||
|
|
Loading…
Reference in a new issue