diff --git a/athenasub/src/athenatime.cpp b/athenasub/src/athenatime.cpp index 642c4cf488f7aeee2bd8ce25a24be44e629ce76f..432efc83a8c6a056407188167260acec0ab22996 100644 --- a/athenasub/src/athenatime.cpp +++ b/athenasub/src/athenatime.cpp @@ -132,11 +132,13 @@ void Time::ParseString(const String &data) { // Break into an array of values array<size_t,4> values; - size_t last = 0; + //size_t last = 0; size_t len = data.Length(); size_t curIndex = 0; char cur = 0; bool gotDecimal = false; + int curValue = 0; + int nDigits = 0; for (size_t i=0;i<len;i++) { cur = data[i]; @@ -147,26 +149,36 @@ void Time::ParseString(const String &data) if (gotDecimal) break; gotDecimal = true; } - values.at(curIndex++) = data.SubToInteger(last,i); - last = i+1; + //values.at(curIndex++) = data.SubToInteger(last,i); + //last = i+1; + values.at(curIndex++) = curValue; + curValue = 0; + nDigits = 0; + } + + // Got a digit + else { + curValue = curValue * 10 + (int)(cur-'0'); + nDigits++; + + // Check if we're already done + if (gotDecimal && nDigits >= 3) { + values.at(curIndex++) = curValue; + break; + } } // Reached end of string if (i == len-1) { - int value = data.SubToInteger(last,len); - size_t digits = len - last; + //int value = data.SubToInteger(last,len); + //size_t digits = len - last; // Ended in decimal, so we gotta normalize it to 3 digits if (gotDecimal) { - if (digits != 3) { - if (digits == 2) value *= 10; - else if (digits == 1) value *= 100; - else if (digits > 3) { - - } - } + if (nDigits == 2) curValue *= 10; + else if (nDigits == 1) curValue *= 100; } - values.at(curIndex++) = value; + values.at(curIndex++) = curValue; } } diff --git a/unit_test/src/athenasub/test_time.cpp b/unit_test/src/athenasub/test_time.cpp index e6c1b2f1eefe383135bc252db4d6188bb5a87507..f63070d1962d2cba8bd681170ea75c466405d75e 100644 --- a/unit_test/src/athenasub/test_time.cpp +++ b/unit_test/src/athenasub/test_time.cpp @@ -36,6 +36,7 @@ #include "../suites.h" #if ATHENASUB_TEST == 1 +#include <iostream> #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> #include "../../../athenasub/include/athenasub/athenasub.h" @@ -48,6 +49,7 @@ class AthenasubTimeTest : public CppUnit::TestFixture { CPPUNIT_TEST(testComparison); CPPUNIT_TEST(testOperators); CPPUNIT_TEST(testSetGet); + CPPUNIT_TEST(testParse); CPPUNIT_TEST_SUITE_END(); private: @@ -104,6 +106,49 @@ public: CPPUNIT_ASSERT(a - 300 == Time(200)); CPPUNIT_ASSERT(a - 600 == Time(0)); } + + void testParse() + { + Time a; + a.ParseString("0"); + CPPUNIT_ASSERT(a.GetMS() == 0); + a.ParseString("5"); + CPPUNIT_ASSERT(a.GetMS() == 5000); + a.ParseString("5.0"); + CPPUNIT_ASSERT(a.GetMS() == 5000); + a.ParseString("5,0"); + CPPUNIT_ASSERT(a.GetMS() == 5000); + a.ParseString("5.00"); + CPPUNIT_ASSERT(a.GetMS() == 5000); + a.ParseString("5.000"); + CPPUNIT_ASSERT(a.GetMS() == 5000); + a.ParseString("5.1"); + CPPUNIT_ASSERT(a.GetMS() == 5100); + a.ParseString("5.12"); + CPPUNIT_ASSERT(a.GetMS() == 5120); + a.ParseString("5.123"); + CPPUNIT_ASSERT(a.GetMS() == 5123); + a.ParseString("5,123"); + CPPUNIT_ASSERT(a.GetMS() == 5123); + a.ParseString("5,1234"); + CPPUNIT_ASSERT(a.GetMS() == 5123); + a.ParseString("5,"); + CPPUNIT_ASSERT(a.GetMS() == 5000); + a.ParseString("05.12"); + CPPUNIT_ASSERT(a.GetMS() == 5120); + a.ParseString("0:05.12"); + CPPUNIT_ASSERT(a.GetMS() == 5120); + a.ParseString("0:15.12"); + CPPUNIT_ASSERT(a.GetMS() == 15120); + a.ParseString("1:15.12"); + CPPUNIT_ASSERT(a.GetMS() == 75120); + a.ParseString("11:15.12"); + CPPUNIT_ASSERT(a.GetMS() == 675120); + a.ParseString("2:11:15.12"); + CPPUNIT_ASSERT(a.GetMS() == 675120+7200000); + a.ParseString("10:11:15.12"); + CPPUNIT_ASSERT(a.GetMS() == 675120+36000000); + } }; CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AthenasubTimeTest,AegisubSuites::athenasub()); diff --git a/unit_test/src/main.cpp b/unit_test/src/main.cpp index 9150e388176429a84b0cdd823e72586a43284fbe..45b422d477498f8734bd63ad1d73b1ea35a1f10e 100644 --- a/unit_test/src/main.cpp +++ b/unit_test/src/main.cpp @@ -40,8 +40,12 @@ #ifdef _MSC_VER +#ifdef _DEBUG +#pragma comment(lib,"cppunitd.lib") +#else #pragma comment(lib,"cppunit.lib") #endif +#endif int main()