Merge pull request #18 from wruppelx/master
[asdcplib.git] / src / KM_util.h
index 2ca17935d7b662fa47e5b1e0c242460c5c040bf5..f3f60f187b3715b9a1d50e7af4412a3254047d8f 100755 (executable)
@@ -36,7 +36,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <KM_error.h>
 #include <KM_tai.h>
 #include <string.h>
-#include <string>
 #include <list>
 
 namespace Kumu
@@ -304,6 +303,18 @@ namespace Kumu
        return false;
       }
 
+      inline bool operator>(const Identifier& rhs) const {
+       ui32_t test_size = xmin(rhs.Size(), SIZE);
+
+       for ( ui32_t i = 0; i < test_size; i++ )
+         {
+           if ( m_Value[i] != rhs.m_Value[i] )
+             return m_Value[i] > rhs.m_Value[i];
+         }
+       
+       return false;
+      }
+
       inline bool operator==(const Identifier& rhs) const {
        if ( rhs.Size() != SIZE ) return false;
        return ( memcmp(m_Value, rhs.m_Value, SIZE) == 0 );
@@ -531,7 +542,7 @@ namespace Kumu
     };
 
   inline void hexdump(const ByteString& buf, FILE* stream = 0) {
-    hexdump(buf.RoData(), buf.Length());
+    hexdump(buf.RoData(), buf.Length(), stream);
   }
 
   // Locates the first occurrence of the null-terminated string s2 in the string s1, where not more
@@ -544,6 +555,27 @@ namespace Kumu
   // adjacent instances of the separator. E.g., "/foo//bar/" will return ["", "foo", "", "bar", ""].
   std::list<std::string> km_token_split(const std::string& str, const std::string& separator);
 
+  // Join the tokens in the given list using delimiter. If prefix is defined then each token
+  // will be concatenated with the prefix before being added to the composite string.
+  template <class T>
+    std::string
+    km_join(const T& list, const std::string& delimiter, const std::string& prefix = "")
+    {
+      std::string result;
+
+      for ( typename T::const_iterator i = list.begin(); i != list.end(); ++i )
+       {
+         if ( i != list.begin() )
+           {
+             result += delimiter;
+           }
+      
+         result += prefix + *i;
+       }
+
+      return result;
+    }
+
 } // namespace Kumu