diff --git a/aegilib/aegilib_2008.vcproj b/aegilib/aegilib_2008.vcproj
index ec11ba3f8..f159ef1b9 100644
--- a/aegilib/aegilib_2008.vcproj
+++ b/aegilib/aegilib_2008.vcproj
@@ -230,6 +230,10 @@
RelativePath=".\src\athenastring.cpp"
>
+
+
diff --git a/aegilib/include/athenasub/athenatime.h b/aegilib/include/athenasub/athenatime.h
index 50fe387d0..a45a1a2d1 100644
--- a/aegilib/include/athenasub/athenatime.h
+++ b/aegilib/include/athenasub/athenatime.h
@@ -37,17 +37,23 @@
namespace Athenasub {
+ class String;
+
// Time class
class Time {
private:
int ms; // Time in milliseconds
public:
- Time() { ms = 0; }
- Time(int milliseconds) { SetMS(milliseconds); }
+ Time();
+ Time(int milliseconds);
+
+ int GetMS() const;
+ void SetMS(int milliseconds);
+
+ String GetString(int ms_precision=3,int h_precision=1) const;
+ void ParseString(const String &data);
- inline void SetMS(int milliseconds) { ms = milliseconds > 0 ? milliseconds : 0; }
- inline int GetMS() const { return ms; }
};
// Operators
diff --git a/aegilib/include/athenasub/interfaces.h b/aegilib/include/athenasub/interfaces.h
index 100739c46..0b36a953f 100644
--- a/aegilib/include/athenasub/interfaces.h
+++ b/aegilib/include/athenasub/interfaces.h
@@ -42,6 +42,9 @@
#include
#include
+class wxInputStream;
+class wxOutputStream;
+
namespace Athenasub {
// Prototypes
diff --git a/aegilib/src/athenatime.cpp b/aegilib/src/athenatime.cpp
new file mode 100644
index 000000000..6b59340af
--- /dev/null
+++ b/aegilib/src/athenatime.cpp
@@ -0,0 +1,163 @@
+// Copyright (c) 2008, Rodrigo Braz Monteiro
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+// * Neither the name of the Aegisub Group nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+// -----------------------------------------------------------------------------
+//
+// AEGISUB/ATHENASUB
+//
+// Website: http://www.aegisub.net
+// Contact: mailto:amz@aegisub.net
+//
+
+#include "athenatime.h"
+#include "utils.h"
+using namespace Athenasub;
+
+
+////////////////
+// Constructors
+Time::Time()
+{
+ ms = 0;
+}
+
+Time::Time(int milliseconds)
+{
+ SetMS(milliseconds);
+}
+
+
+///////////////////
+// Getters/setters
+void Time::SetMS(int milliseconds)
+{
+ ms = Max(milliseconds,0);
+}
+
+int Time::GetMS() const
+{
+ return ms;
+}
+
+
+//////////////////////////////////
+// Generates a string from a time
+String Time::GetString(int ms_precision,int h_precision) const
+{
+ // Enforce sanity
+ ms_precision = Mid(0,ms_precision,3);
+ h_precision = Mid(0,h_precision,2);
+
+ // Generate values
+ int _ms = GetMS();
+ int h = _ms / 3600000;
+ _ms -= h*3600000;
+ int min = _ms / 60000;
+ _ms -= min*60000;
+ int s = _ms / 1000;
+ _ms -= s*1000;
+
+ // Cap hour value
+ if (h > 9 && h_precision == 1) {
+ h = 9;
+ min = 59;
+ s = 59;
+ _ms = 999;
+ }
+
+ // Modify ms to account for precision
+ if (ms_precision == 2) _ms /= 10;
+ else if (ms_precision == 1) _ms /= 100;
+ else if (ms_precision == 0) _ms = 0;
+
+ // Asserts
+ assert(h >= 0 && h <= 9);
+ assert(min >= 0 && min <= 59);
+ assert(s >= 0 && s <= 59);
+ assert(_ms >= 0 && _ms <= 999);
+
+ // Get write buffer
+ String final;
+ size_t size = 7+h_precision+ms_precision;
+ size_t pos = 0;
+ //wxChar *buffer = final.GetWriteBuf(size);
+ Character temp[16];
+ final.resize(size);
+
+ // Write time
+ final.WriteNumber(temp,h,h_precision,pos);
+ final.WriteChar(':',pos);
+ final.WriteNumber(temp,min,2,pos);
+ final.WriteChar(':',pos);
+ final.WriteNumber(temp,s,2,pos);
+ final.WriteChar('.',pos);
+ final.WriteNumber(temp,_ms,ms_precision,pos);
+
+ // Write terminator
+ //final.WriteText("\0",1,pos);
+
+ // Restore string's state and return
+ final.SetSize(pos-1);
+ return final;
+}
+
+
+///////////////////////////////
+// Parses a string into a time
+void Time::ParseString(const String &data)
+{
+ // Break into an array of values
+ array values;
+ size_t last = 0;
+ size_t len = data.Length();
+ size_t curIndex = 0;
+ char cur = 0;
+ for (size_t i=0;i=0;) {
+ accum += values[i] * mult[curIndex-i];
+ }
+
+ // Set
+ SetMS((int)accum);
+}
diff --git a/aegilib/src/formats/format_ass_dialogue.cpp b/aegilib/src/formats/format_ass_dialogue.cpp
index 6ae61bcdb..9f300c513 100644
--- a/aegilib/src/formats/format_ass_dialogue.cpp
+++ b/aegilib/src/formats/format_ass_dialogue.cpp
@@ -62,103 +62,6 @@ DialogueASS::DialogueASS(const String &data,int version)
}
-//////////////////////////////////
-// Generates a string from a time
-String GetTimeString(const Time& time,int ms_precision,int h_precision)
-{
- // Enforce sanity
- ms_precision = Mid(0,ms_precision,3);
- h_precision = Mid(0,h_precision,2);
-
- // Generate values
- int _ms = time.GetMS();
- int h = _ms / 3600000;
- _ms -= h*3600000;
- int min = _ms / 60000;
- _ms -= min*60000;
- int s = _ms / 1000;
- _ms -= s*1000;
-
- // Cap hour value
- if (h > 9 && h_precision == 1) {
- h = 9;
- min = 59;
- s = 59;
- _ms = 999;
- }
-
- // Modify ms to account for precision
- if (ms_precision == 2) _ms /= 10;
- else if (ms_precision == 1) _ms /= 100;
- else if (ms_precision == 0) _ms = 0;
-
- // Asserts
- assert(h >= 0 && h <= 9);
- assert(min >= 0 && min <= 59);
- assert(s >= 0 && s <= 59);
- assert(_ms >= 0 && _ms <= 999);
-
- // Get write buffer
- String final;
- size_t size = 7+h_precision+ms_precision;
- size_t pos = 0;
- //wxChar *buffer = final.GetWriteBuf(size);
- Character temp[16];
- final.resize(size);
-
- // Write time
- final.WriteNumber(temp,h,h_precision,pos);
- final.WriteChar(':',pos);
- final.WriteNumber(temp,min,2,pos);
- final.WriteChar(':',pos);
- final.WriteNumber(temp,s,2,pos);
- final.WriteChar('.',pos);
- final.WriteNumber(temp,_ms,ms_precision,pos);
-
- // Write terminator
- //final.WriteText("\0",1,pos);
-
- // Restore string's state and return
- final.SetSize(pos-1);
- return final;
-}
-
-
-///////////////////////////////
-// Parses a string into a time
-Time ParseTimeString(const String &data)
-{
- // Break into an array of values
- array values;
- size_t last = 0;
- size_t len = data.Length();
- size_t curIndex = 0;
- char cur = 0;
- for (size_t i=0;i=0;) {
- accum += values[i] * mult[curIndex-i];
- }
- return Time((int)accum);
-}
-
-
//////////////////
// Parse ASS Data
bool DialogueASS::Parse(String rawData, int version)
@@ -194,8 +97,8 @@ bool DialogueASS::Parse(String rawData, int version)
}
// Get times
- time[0] = ParseTimeString(tkn.GetString());
- time[1] = ParseTimeString(tkn.GetString());
+ time[0].ParseString(tkn.GetString());
+ time[1].ParseString(tkn.GetString());
// Get style and actor
text[1] = tkn.GetString(true);
@@ -267,7 +170,7 @@ String DialogueASS::ToText(int version) const
// Write times
for (size_t i=0;i<2;i++) {
- String tempStr = GetTimeString(time[i],2,1);
+ String tempStr = time[i].GetString(2,1);
buffer.WriteText(&tempStr[0],10,pos);
buffer.WriteChar(',',pos);
}