1#ifndef ROSE_StringUtility_SplitJoin_H
2#define ROSE_StringUtility_SplitJoin_H
4#include <Rose/Constants.h>
14namespace StringUtility {
34ROSE_UTIL_API std::vector<std::string>
split(
const std::string &separator,
const std::string &str,
size_t maxparts =
UNLIMITED,
35 bool trim_white_space =
false);
36ROSE_UTIL_API std::vector<std::string>
split(
char separator,
const std::string &str,
size_t maxparts =
UNLIMITED,
37 bool trim_white_space =
false);
44ROSE_UTIL_API std::list<std::string>
tokenize(
const std::string&,
char delim);
53template<
class Iterator>
54std::string
join_range(
const std::string &separator, Iterator begin, Iterator end) {
55 std::ostringstream retval;
56 for (Iterator i=begin; i!=end; ++i)
57 retval <<(i==begin ? std::string() : separator) <<*i;
61template<
class Container>
62std::string
join(
const std::string &separator,
const Container &container) {
63 return join_range(separator, container.begin(), container.end());
66template<
class Container>
67std::string
join(
char separator,
const Container &container) {
68 return join_range(std::string(1, separator), container.begin(), container.end());
71ROSE_UTIL_API std::string
join(
const std::string &separator,
char *strings[],
size_t nstrings);
72ROSE_UTIL_API std::string
join(
const std::string &separator,
const char *strings[],
size_t nstrings);
73ROSE_UTIL_API std::string
join(
char separator,
char *strings[],
size_t nstrings);
74ROSE_UTIL_API std::string
join(
char separator,
const char *strings[],
size_t nstrings);
99ROSE_UTIL_API std::string
joinEnglish(
const std::vector<std::string> &phrases,
100 const std::string &separator =
",",
101 const std::string &finalIntro =
"and");
102ROSE_UTIL_API std::string
joinEnglish(
const std::set<std::string> &phrases,
103 const std::string &separator =
",",
104 const std::string &finalIntro =
"and");
118ROSE_UTIL_API std::string
listToString(
const std::list<int>&,
bool separateStrings =
false);
126ROSE_UTIL_API std::string
listToString(
const std::list<std::string>&,
bool separateStrings =
false);
127ROSE_UTIL_API std::string
listToString(
const std::vector<std::string>&,
bool separateStrings =
false);
144ROSE_UTIL_API
void splitStringIntoStrings(
const std::string& inputString,
char separator, std::vector<std::string>& stringList);
ROSE_UTIL_API std::string listToString(const std::list< int > &, bool separateStrings=false)
Generate a string from a list of integers.
ROSE_UTIL_API void splitStringIntoStrings(const std::string &inputString, char separator, std::vector< std::string > &stringList)
Splits string into substring based on a separator character.
ROSE_UTIL_API std::vector< std::string > split(const std::string &separator, const std::string &str, size_t maxparts=UNLIMITED, bool trim_white_space=false)
Splits strings into parts.
std::string join(const std::string &separator, const Container &container)
Join individual items to form a single string.
ROSE_UTIL_API std::list< std::string > stringToList(const std::string &)
Split a string into substrings at line feeds.
ROSE_UTIL_API std::list< std::string > tokenize(const std::string &, char delim)
Split a string into a list based on a separator character.
std::string join_range(const std::string &separator, Iterator begin, Iterator end)
Join individual items to form a single string.
ROSE_UTIL_API std::string joinEnglish(const std::vector< std::string > &phrases, const std::string &separator=",", const std::string &finalIntro="and")
Join strings as if they were English prose.
const size_t UNLIMITED
Effectively unlimited size.