removed nascent ST2052-1 support pending completion
[asdcplib.git] / src / KM_util.cpp
index d6b71418ecc2648d76a8fd3d3c95a8dbcc9a9dfa..333b00a8c4876dd57f0c8205ad86a12c9133d903 100755 (executable)
@@ -812,7 +812,7 @@ Kumu::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const
   return str_buf;
 }
 
-//
+// ^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(?:([+-]\d{2}):(\d{2}))?)?$
 bool
 Kumu::Timestamp::DecodeString(const char* datestr)
 {
@@ -825,6 +825,9 @@ Kumu::Timestamp::DecodeString(const char* datestr)
 
   ui32_t char_count = 10;
   TAI::caltime YMDhms;
+  YMDhms.hour = 0;
+  YMDhms.minute = 0;
+  YMDhms.second = 0;
   YMDhms.offset = 0;
   YMDhms.date.year = atoi(datestr);
   YMDhms.date.month = atoi(datestr + 5);
@@ -913,7 +916,7 @@ bool
 Kumu::Timestamp::Unarchive(MemIOReader* Reader)
 {
   ui16_t year;
-  ui8_t month, day, hour, minute, second;
+  ui8_t month, day, hour, minute, second, tick;
 
   assert(Reader);
   if ( ! Reader->ReadUi16BE(&year) ) return false;
@@ -922,6 +925,7 @@ Kumu::Timestamp::Unarchive(MemIOReader* Reader)
   if ( ! Reader->ReadUi8(&hour) ) return false;
   if ( ! Reader->ReadUi8(&minute) ) return false;
   if ( ! Reader->ReadUi8(&second) ) return false;
+  if ( ! Reader->ReadUi8(&tick) ) return false;
   SetComponents(year, month, day, hour, minute, second);
   return true;
 }
@@ -933,7 +937,7 @@ Kumu::Timestamp::Archive(MemIOWriter* Writer) const
   assert(Writer);
 
   ui16_t year;
-  ui8_t month, day, hour, minute, second;
+  ui8_t month, day, hour, minute, second, tick = 0;
   GetComponents(year, month, day, hour, minute, second);
 
   if ( ! Writer->WriteUi16BE(year) ) return false;     
@@ -942,6 +946,7 @@ Kumu::Timestamp::Archive(MemIOWriter* Writer) const
   if ( ! Writer->WriteUi8(hour) ) return false;
   if ( ! Writer->WriteUi8(minute) ) return false;
   if ( ! Writer->WriteUi8(second) ) return false;
+  if ( ! Writer->WriteUi8(tick) ) return false;
   return true;
 }
 
@@ -952,6 +957,15 @@ Kumu::Timestamp::GetCTime() const
   return m_Timestamp.x - ui64_C(4611686018427387914);
 }
 
+//
+void
+Kumu::Timestamp::SetCTime(const ui64_t& ctime)
+{
+  m_Timestamp.x = ctime + ui64_C(4611686018427387914);
+}
+
+
+
 
 //------------------------------------------------------------------------------------------
 
@@ -1115,6 +1129,64 @@ Kumu::ByteString::Append(const byte_t* buf, ui32_t buf_len)
   return result;
 }
 
+//------------------------------------------------------------------------------------------
+
+//
+const char*
+Kumu::km_strnstr(const char *s, const char *find, size_t slen)
+{
+  char c, sc;
+  size_t len;
+
+  if ( ( c = *find++ ) != '\0' )
+    {
+      len = strlen(find);
+      do
+       {
+         do
+           {
+             if ( slen-- < 1 || ( sc = *s++ ) == '\0' )
+               return 0;
+           }
+         while ( sc != c );
+
+         if ( len > slen )
+           return 0;
+       }
+      while ( strncmp(s, find, len) != 0 );
+      --s;
+    }
+
+  return s;
+}
+
+//
+std::list<std::string>
+Kumu::km_token_split(const std::string& str, const std::string& separator)
+{
+  std::list<std::string> components;
+  const char* pstr = str.c_str();
+  const char* r = strstr(pstr, separator.c_str());
+
+  while ( r != 0 )
+    {
+      assert(r >= pstr);
+      if ( r > pstr )
+       {
+         std::string tmp_str;
+         tmp_str.assign(pstr, r - pstr);
+         components.push_back(tmp_str);
+       }
+
+      pstr = r + separator.size();
+      r = strstr(pstr, separator.c_str());
+    }
+      
+  if( strlen(pstr) > 0 )
+    components.push_back(std::string(pstr));
+
+  return components;
+}
 
 //
 // end KM_util.cpp