#ifndef __STRINGFUNC_HXX
#define __STRINGFUNC_HXX
+#include <stdio.h>
#include <list>
+#include <numeric>
+#include <set>
#include <vector>
#include <string>
#include <sstream>
const std::string& trim_list= std::string()
);
+void split_string(
+ const std::string& str,
+ std::vector< std::string >& result,
+ const std::string& delimiter= "\n",
+ bool omit_empty= false,
+ const std::string& trim_list= std::string()
+);
+
std::list< std::string > split_string(
const std::string& str,
const std::string& delimiter = "\n",
const std::string& trim_list= std::string()
);
+struct concatenator {
+ std::string delim;
-std::string join_string(
- const std::list< std::string >& parts,
+ concatenator (const std::string &delim) : delim (delim) { }
+
+ inline std::string operator() (const std::string &acc, const std::string &elt) const
+ { return acc + delim + elt; }
+};
+
+template<typename Iter>
+std::string
+join_string (
+ Iter first,
+ Iter last,
+ const std::string &delimiter = "\n"
+)
+{
+ if (first == last) { return ""; }
+
+ const std::string &init = *first++;
+ if (first == last) { return init; }
+
+ return std::accumulate (first, last, init, concatenator (delimiter));
+}
+
+/**
+ * @brief joins a container of strings into a single string.
+ *
+ * This funtion is (basically) the reverse operation of @a split_string.
+ *
+ * @param parts the container of strings.
+ * @param delimiter the delimiter to insert between the strings.
+ * @return the joined string.
+ */
+template<typename Cont>
+inline std::string join_string(
+ const Cont& parts,
const std::string& delimiter = "\n"
-);
+)
+{ return join_string (parts.begin (), parts.end (), delimiter); }
std::string join_string(
- const std::vector< std::string >& parts,
+ const char *const parts [],
const std::string& delimiter = "\n"
);
-
/*
** conversions:
*/
} // eo to_string(const T&)
+/**
+ * Create a string with types shortened in texts describing C++ types
+ *
+ * for example: std::list<some_long_type, std::allocator<some_long_type> >
+ * --> std::list<some_long_type, _alloc_>
+ *
+ * and std::basic_string<char, std::char_traits<char>, std::allocator<char> >
+ * --> std::string
+ */
+std::string shorten_stl_types(const std::string &input);
+
+std::string base64_encode(const std::string &input, bool one_line=true);
+std::string base64_decode(const std::string &input, bool one_line=true);
+
} // eo namespace I2n