#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()
);
+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:
*/
std::string html_entities(std::string str);
std::string html_entities_to_console(std::string str);
+inline std::string html_entities_iso (const std::string &str)
+{
+ return html_entities (iso_to_utf8 (str));
+}
+
typedef std::pair<std::string::size_type, std::string::size_type> CommentZone;
std::vector<CommentZone> find_html_comments(const std::string &str);
void remove_html_comments(std::string &str);