[563535] Time literals in arrays or structs would not been parsed

With the last fix time literals in arrays or structs would not have been
parsed correctly. This is improved now.

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=563535
Change-Id: Ib550a4e8192468f340022277c3607cddc9584be7
diff --git a/src/core/datatypes/forte_time.cpp b/src/core/datatypes/forte_time.cpp
index 6767b4f..17ffb22 100644
--- a/src/core/datatypes/forte_time.cpp
+++ b/src/core/datatypes/forte_time.cpp
@@ -55,17 +55,16 @@
         nRetVal++;

       }

       TValueType nTimeFactor = 1;

+      bool bEnd = false;

       do {

         TValueType nBuf = forte::core::util::strtol(paValue, &pcEnd, 10);

         switch(tolower(*pcEnd)){

           case 'd':

             nTimeFactor = 24 * 60 * 60 * cgForteTimeBaseUnitsPerSecond;

             break;

-

           case 'h':

             nTimeFactor = 60 * 60 * cgForteTimeBaseUnitsPerSecond;

             break;

-

           case 'm':

             if('s' == tolower(*(pcEnd + 1))) {

               nTimeFactor = cgForteTimeBaseUnitsPerSecond / forte::core::constants::cMillisecondsPerSecond;

@@ -97,13 +96,23 @@
             //ignore leading underscores

             break;

           default:

-            // we haven't got a unit mark it as error

-            return -1;

+            if((pcEnd != paValue) || (0 == nIntVal)){   //we could not parse anything yet so wrong literal

+              //we have a number without unit or it is the first entry which we could not pars then this is an error

+              return -1;

+            }

+             // we are in an array and at the end of the literal

+            bEnd = true;

+            break;

         }

-        nRetVal += static_cast<int>(pcEnd - paValue) + 1;

-        paValue = pcEnd + 1;

+        nRetVal += static_cast<int>(pcEnd - paValue);

+        paValue = pcEnd;

+        if(!bEnd) {

+          ++nRetVal;

+          ++paValue;

+        }

         nIntVal += (nBuf * nTimeFactor * nTimeSignFactor);

-      } while('\0' != *paValue);

+      } while((!bEnd) && ('\0' != *paValue));

+

     } else {

       return -1;

     }

diff --git a/tests/core/datatypes/CIEC_TIME_test.cpp b/tests/core/datatypes/CIEC_TIME_test.cpp
index 93ca8f6..905de44 100644
--- a/tests/core/datatypes/CIEC_TIME_test.cpp
+++ b/tests/core/datatypes/CIEC_TIME_test.cpp
@@ -432,4 +432,18 @@
   BOOST_CHECK_EQUAL(time.getInNanoSeconds(), 0);
 }
 
+BOOST_AUTO_TEST_CASE(parse_time_in_struct_or_array_literal)
+{
+  CIEC_TIME time;
+
+  BOOST_CHECK_EQUAL(7, time.fromString("T#999ms, "));
+  BOOST_CHECK_EQUAL(time.getInMilliSeconds(), 999);
+
+  BOOST_CHECK_EQUAL(6, time.fromString("T#23ms , "));
+  BOOST_CHECK_EQUAL(time.getInMilliSeconds(), 23);
+
+  BOOST_CHECK_EQUAL(12, time.fromString("T#10325643us,"));
+  BOOST_CHECK_EQUAL(time.getInMicroSeconds(), 10325643);
+}
+
 BOOST_AUTO_TEST_SUITE_END()