Uncrustify AssTime

Originally committed to SVN as r6122.
This commit is contained in:
Thomas Goyne 2011-12-22 21:28:41 +00:00
parent e36759a3b2
commit de9583004d
2 changed files with 68 additions and 180 deletions

View file

@ -34,213 +34,99 @@
/// @ingroup subs_storage /// @ingroup subs_storage
/// ///
////////////
// Includes
#include "config.h" #include "config.h"
#include "ass_time.h"
#ifndef AGI_PRE #ifndef AGI_PRE
#include <math.h>
#include <algorithm> #include <algorithm>
#include <fstream> #include <cmath>
#include <wx/regex.h>
#endif #endif
#include "ass_time.h"
#include "utils.h" #include "utils.h"
/// @brief AssTime constructors
AssTime::AssTime() : time(0) { }
AssTime::AssTime(int time) { SetMS(time); } AssTime::AssTime(int time) { SetMS(time); }
void AssTime::ParseASS(wxString const& text) {
int ms = 0;
size_t pos = 0, end = 0;
int colons = text.Freq(':');
/// @brief Note that this function is atomic, it won't touch the values if it's invalid. --------------- Parses from ASS
/// @param text
/// @return
///
void AssTime::ParseASS (const wxString text) {
// Prepare
size_t pos = 0;
size_t end = 0;
long th=0,tm=0,tms=0;
// Count the number of colons
size_t len = text.Length();
int colons = 0;
for (pos=0;pos<len;pos++) if (text[pos] == ':') colons++;
pos = 0;
// Set start so that there are only two colons at most // Set start so that there are only two colons at most
if (colons > 2) { for (; colons > 2; --colons) pos = text.find(':', pos) + 1;
for (pos=0;pos<len;pos++) {
if (text[pos] == ':') { // Hours
colons--; if (colons == 2) {
if (colons == 2) break; while (text[end++] != ':') { }
} ms += AegiStringToInt(text, pos, end) * 60 * 60 * 1000;
} pos = end;
pos++;
end = pos;
} }
try { // Minutes
// Hours if (colons >= 1) {
if (colons == 2) { while (text[end++] != ':') { }
while (text[end++] != ':') {}; ms += AegiStringToInt(text, pos, end) * 60 * 1000;
th = AegiStringToInt(text,pos,end);
pos = end;
}
// Minutes
if (colons >= 1) {
while (text[end++] != ':') {};
tm = AegiStringToInt(text,pos,end);
pos = end;
}
// Miliseconds (includes seconds)
end = text.Length();
tms = AegiStringToFix(text,3,pos,end);
} }
// Something went wrong, don't change anything // Milliseconds (includes seconds)
catch (...) { ms += AegiStringToFix(text, 3, end, text.size());
return;
}
// OK, set values SetMS(ms);
SetMS(tms + tm*60000 + th*3600000);
} }
/// @brief AssTime conversion to/from miliseconds int AssTime::GetMS() const {
/// @return
///
int AssTime::GetMS () const {
return time / 10 * 10; return time / 10 * 10;
} }
void AssTime::SetMS(int ms) {
/// @brief DOCME
/// @param _ms
///
void AssTime::SetMS (int ms) {
time = mid(0, ms, 10 * 60 * 60 * 1000 - 1); time = mid(0, ms, 10 * 60 * 60 * 1000 - 1);
} }
/// @brief ASS Formated
/// @param msPrecision
/// @return
///
wxString AssTime::GetASSFormated (bool msPrecision) const { wxString AssTime::GetASSFormated (bool msPrecision) const {
int ms = msPrecision ? time : GetMS();
int h = ms / (1000 * 60 * 60);
int m = (ms / (1000 * 60)) % 60;
int s = (ms / 1000) % 60;
ms = ms % 1000;
if (msPrecision) if (msPrecision)
return wxString::Format("%01i:%02i:%02i.%03i",h,m,s,ms); return wxString::Format("%d:%02d:%02d.%03d", GetTimeHours(), GetTimeMinutes(), GetTimeSeconds(), GetTimeMiliseconds());
else else
return wxString::Format("%01i:%02i:%02i.%02i",h,m,s,ms/10); return wxString::Format("%d:%02d:%02d.%02d", GetTimeHours(), GetTimeMinutes(), GetTimeSeconds(), GetTimeCentiseconds());
} }
/// @brief AssTime comparison bool operator < (AssTime t1, AssTime t2) {
/// @param t1 return t1.GetMS() < t2.GetMS();
/// @param t2
/// @return
///
bool operator < (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() < t2.GetMS());
} }
bool operator > (AssTime t1, AssTime t2) {
/// @brief DOCME return t1.GetMS() > t2.GetMS();
/// @param t1
/// @param t2
/// @return
///
bool operator > (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() > t2.GetMS());
} }
bool operator <= (AssTime t1, AssTime t2) {
/// @brief DOCME return t1.GetMS() <= t2.GetMS();
/// @param t1
/// @param t2
/// @return
///
bool operator <= (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() <= t2.GetMS());
} }
bool operator >= (AssTime t1, AssTime t2) {
/// @brief DOCME return t1.GetMS() >= t2.GetMS();
/// @param t1
/// @param t2
/// @return
///
bool operator >= (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() >= t2.GetMS());
} }
bool operator == (AssTime t1, AssTime t2) {
/// @brief DOCME return t1.GetMS() == t2.GetMS();
/// @param t1
/// @param t2
/// @return
///
bool operator == (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() == t2.GetMS());
} }
bool operator != (AssTime t1, AssTime t2) {
/// @brief DOCME return t1.GetMS() != t2.GetMS();
/// @param t1
/// @param t2
/// @return
///
bool operator != (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() != t2.GetMS());
} }
AssTime operator + (const AssTime &t1, const AssTime &t2) { AssTime operator + (AssTime t1, AssTime t2) {
return AssTime(t1.GetMS() + t2.GetMS()); return AssTime(t1.GetMS() + t2.GetMS());
} }
AssTime operator - (const AssTime &t1, const AssTime &t2) { AssTime operator - (AssTime t1, AssTime t2) {
return AssTime(t1.GetMS() - t2.GetMS()); return AssTime(t1.GetMS() - t2.GetMS());
} }
/// @brief Get int AssTime::GetTimeHours() const { return time / 3600000; }
/// @return int AssTime::GetTimeMinutes() const { return (time % 3600000) / 60000; }
/// int AssTime::GetTimeSeconds() const { return (time % 60000) / 1000; }
int AssTime::GetTimeHours() { return time / 3600000; } int AssTime::GetTimeMiliseconds() const { return (time % 1000); }
int AssTime::GetTimeCentiseconds() const { return (time % 1000) / 10; }
/// @brief DOCME
/// @return
///
int AssTime::GetTimeMinutes() { return (time % 3600000)/60000; }
/// @brief DOCME
/// @return
///
int AssTime::GetTimeSeconds() { return (time % 60000)/1000; }
/// @brief DOCME
/// @return
///
int AssTime::GetTimeMiliseconds() { return (time % 1000); }
/// @brief DOCME
/// @return
///
int AssTime::GetTimeCentiseconds() { return (time % 1000)/10; }
FractionalTime::FractionalTime(agi::vfr::Framerate fps, bool dropframe) FractionalTime::FractionalTime(agi::vfr::Framerate fps, bool dropframe)
: fps(fps) : fps(fps)

View file

@ -37,8 +37,6 @@
#pragma once #pragma once
#ifndef AGI_PRE #ifndef AGI_PRE
#include <stdint.h>
#include <wx/string.h> #include <wx/string.h>
#endif #endif
@ -50,35 +48,39 @@
/// ///
/// DOCME /// DOCME
class AssTime { class AssTime {
/// Time in miliseconds /// Time in milliseconds
int time; int time;
public: public:
AssTime(); AssTime(int ms = 0);
AssTime(int ms);
int GetTimeHours(); int GetTimeHours() const; ///< Get the hours portion of this time
int GetTimeMinutes(); int GetTimeMinutes() const; ///< Get the minutes portion of this time
int GetTimeSeconds(); int GetTimeSeconds() const; ///< Get the seconds portion of this time
int GetTimeMiliseconds(); int GetTimeMiliseconds() const; ///< Get the miliseconds portion of this time
int GetTimeCentiseconds(); int GetTimeCentiseconds() const; ///< Get the centiseconds portion of this time
int GetMS() const; ///< Returns milliseconds /// Get millisecond, rounded to centisecond precision
void SetMS(int ms); ///< Sets values to milliseconds with bounds-checking int GetMS() const;
void ParseASS(const wxString text); ///< Sets value to text-form time, in ASS format /// Sets values to milliseconds with bounds-checking
wxString GetASSFormated(bool ms=false) const; ///< Returns the ASS representation of time void SetMS(int ms);
/// 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;
}; };
// Comparison operators // Comparison operators
bool operator == (const AssTime &t1, const AssTime &t2); bool operator == (AssTime t1, AssTime t2);
bool operator != (const AssTime &t1, const AssTime &t2); bool operator != (AssTime t1, AssTime t2);
bool operator < (const AssTime &t1, const AssTime &t2); bool operator < (AssTime t1, AssTime t2);
bool operator > (const AssTime &t1, const AssTime &t2); bool operator > (AssTime t1, AssTime t2);
bool operator <= (const AssTime &t1, const AssTime &t2); bool operator <= (AssTime t1, AssTime t2);
bool operator >= (const AssTime &t1, const AssTime &t2); bool operator >= (AssTime t1, AssTime t2);
// Arithmetic operators // Arithmetic operators
AssTime operator + (const AssTime &t1, const AssTime &t2); AssTime operator + (AssTime t1, AssTime t2);
AssTime operator - (const AssTime &t1, const AssTime &t2); AssTime operator - (AssTime t1, AssTime t2);
/// DOCME /// DOCME
/// @class FractionalTime /// @class FractionalTime