ROSE  0.11.96.11
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 <sstream>
9 #include <string>
10 #include <vector>
11 
12 namespace Rose {
13 namespace StringUtility {
14 
16 // Splitting and joining strings
18 
33 ROSE_UTIL_API std::vector<std::string> split(const std::string &separator, const std::string &str, size_t maxparts = UNLIMITED,
34  bool trim_white_space = false);
35 ROSE_UTIL_API std::vector<std::string> split(char separator, const std::string &str, size_t maxparts = UNLIMITED,
36  bool trim_white_space = false);
43 ROSE_UTIL_API std::list<std::string> tokenize(const std::string&, char delim);
44 
52 template<class Iterator>
53 std::string join_range(const std::string &separator, Iterator begin, Iterator end) {
54  std::ostringstream retval;
55  for (Iterator i=begin; i!=end; ++i)
56  retval <<(i==begin ? std::string() : separator) <<*i;
57  return retval.str();
58 }
59 
60 template<class Container>
61 std::string join(const std::string &separator, const Container &container) {
62  return join_range(separator, container.begin(), container.end());
63 }
64 
65 template<class Container>
66 std::string join(char separator, const Container &container) {
67  return join_range(std::string(1, separator), container.begin(), container.end());
68 }
69 
70 ROSE_UTIL_API std::string join(const std::string &separator, char *strings[], size_t nstrings);
71 ROSE_UTIL_API std::string join(const std::string &separator, const char *strings[], size_t nstrings);
72 ROSE_UTIL_API std::string join(char separator, char *strings[], size_t nstrings);
73 ROSE_UTIL_API std::string join(char separator, const char *strings[], size_t nstrings);
74 
96 ROSE_UTIL_API std::string joinEnglish(const std::vector<std::string> &phrases,
97  const std::string &separator = ",",
98  const std::string &finalIntro = "and");
99 
101 // Container versus scalar functions
102 //
103 // Functions that convert containers of things to a string and vice versa.
105 
111 ROSE_UTIL_API std::string listToString(const std::list<int>&, bool separateStrings = false);
112 
119 ROSE_UTIL_API std::string listToString(const std::list<std::string>&, bool separateStrings = false);
120 ROSE_UTIL_API std::string listToString(const std::vector<std::string>&, bool separateStrings = false);
131 ROSE_UTIL_API std::list<std::string> stringToList(const std::string&);
132 
137 ROSE_UTIL_API void splitStringIntoStrings(const std::string& inputString, char separator, std::vector<std::string>& stringList);
138 
139 } // namespace
140 } // namespace
141 
142 #endif
Rose::StringUtility::split
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.
Rose::StringUtility::joinEnglish
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.
Rose::StringUtility::join_range
std::string join_range(const std::string &separator, Iterator begin, Iterator end)
Join individual items to form a single string.
Definition: SplitJoin.h:53
Rose::StringUtility::stringToList
ROSE_UTIL_API std::list< std::string > stringToList(const std::string &)
Split a string into substrings at line feeds.
Rose::StringUtility::tokenize
ROSE_UTIL_API std::list< std::string > tokenize(const std::string &, char delim)
Split a string into a list based on a separator character.
Rose::StringUtility::splitStringIntoStrings
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::StringUtility::listToString
ROSE_UTIL_API std::string listToString(const std::list< int > &, bool separateStrings=false)
Generate a string from a list of integers.
Rose::StringUtility::join
std::string join(const std::string &separator, const Container &container)
Join individual items to form a single string.
Definition: SplitJoin.h:61
Rose
Main namespace for the ROSE library.
Definition: BinaryTutorial.dox:3
Rose::UNLIMITED
const size_t UNLIMITED(static_cast< size_t >(-1))
Effictively unlimited size.