]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/utils.h
Add some utility functions for joining strings
[libs/core.git] / source / strings / utils.h
index 6e145916f5cd1bbe0685525c5d3646668670a703..f7e9433fd2d07a3e7496e7e7735af77d5dfff4c0 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of libmspstrings
-Copyright © 2006-2008 Mikko Rasa
-Distributed under the LGPL
-*/
-
 #ifndef MSP_STRINGS_UTILS_H_
 #define MSP_STRINGS_UTILS_H_
 
@@ -63,17 +56,19 @@ std::vector<std::string> split_fields(const std::string &str, const std::string
 separators will cause an empty string to be placed in the result. */
 std::vector<std::string> split_fields(const std::string &str, char sep, int max_split = -1);
 
+/** Appends a string to another, using a separator if both are non-empty. */
+std::string &append(std::string &str, const std::string &sep, const std::string &other);
+
+/** Joins two strings, using a separator if both are non-empty. */
+std::string join(const std::string &str1, const std::string &sep, const std::string &str2);
+
 /** Concatenates strings from an iterator range. */
 template<typename Iter>
 std::string join(Iter begin, Iter end, const std::string &sep = " ")
 {
        std::string result;
        for(Iter i=begin; i!=end; ++i)
-       {
-               if(i!=begin)
-                       result += sep;
-               result += *i;
-       }
+               append(result, sep, *i);
 
        return result;
 }