ROSE 0.11.145.192
SplitJoin.h
1#ifndef ROSE_StringUtility_SplitJoin_H
2#define ROSE_StringUtility_SplitJoin_H
3
4#include <Rose/Constants.h>
5#include <rosedll.h>
6
7#include <list>
8#include <set>
9#include <sstream>
10#include <string>
11#include <vector>
12
13namespace Rose {
14namespace StringUtility {
15
17// Splitting and joining strings
19
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);
45
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;
58 return retval.str();
59}
60
61template<class Container>
62std::string join(const std::string &separator, const Container &container) {
63 return join_range(separator, container.begin(), container.end());
64}
65
66template<class Container>
67std::string join(char separator, const Container &container) {
68 return join_range(std::string(1, separator), container.begin(), container.end());
69}
70
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);
75
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");
108// Container versus scalar functions
109//
110// Functions that convert containers of things to a string and vice versa.
112
118ROSE_UTIL_API std::string listToString(const std::list<int>&, bool separateStrings = false);
119
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);
138ROSE_UTIL_API std::list<std::string> stringToList(const std::string&);
139
144ROSE_UTIL_API void splitStringIntoStrings(const std::string& inputString, char separator, std::vector<std::string>& stringList);
145
146} // namespace
147} // namespace
148
149#endif
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.
Definition SplitJoin.h:62
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.
Definition SplitJoin.h:54
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.
The ROSE library.
const size_t UNLIMITED
Effectively unlimited size.
Definition Constants.h:19