big change rollup
[asdcplib.git] / src / KM_util.cpp
index 803b0ed6a5cf09df2e1c946589ed81ff94e86ce2..333b00a8c4876dd57f0c8205ad86a12c9133d903 100755 (executable)
@@ -1129,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