14#include <boost/algorithm/string.hpp>
29 std::vector<std::string> result;
32 std::regex paragraph_split {
"\\n\\s*\\n"};
36 std::regex_token_iterator cur(text.begin(), text.end(), paragraph_split, -1);
37 std::regex_token_iterator<std::string::const_iterator> end;
39 for (; cur != end; ++cur)
41 std::string paragraph = *cur;
42 boost::trim(paragraph);
43 if (paragraph.size() > 0)
45 result.push_back(paragraph);
55std::vector<std::string>
split(
const std::string& line,
const std::string& separators)
57 std::vector<std::string> result;
58 boost::algorithm::split(result, line, boost::algorithm::is_any_of(separators));
66std::string
read_text(
const std::string& filename,
bool warn)
68 std::ifstream in(filename.c_str());
81 in.unsetf(std::ios::skipws);
85 std::istream_iterator<char>(in),
86 std::istream_iterator<char>(),
99 std::regex src {
"%[^\\n]*\\n"};
101 std::string dest(
"\n");
102 return std::regex_replace(text, src, dest);
110 std::regex src {
"\\s"};
111 std::string dest(
"");
112 return std::regex_replace(text, src, dest);
120std::string
regex_replace(
const std::string& src,
const std::string& dest,
const std::string& text)
122 return std::regex_replace(text, std::regex(src), dest);
129std::vector<std::string>
regex_split(
const std::string& text,
const std::string& sep)
131 std::vector<std::string> result;
133 std::regex paragraph_split { sep };
136 std::sregex_token_iterator cur(text.begin(), text.end(), paragraph_split, -1);
137 std::sregex_token_iterator end;
138 for (; cur != end; ++cur)
140 std::string word = *cur;
144 result.push_back(word);
155std::vector<std::string>
word_wrap_line(
const std::string& line,
unsigned int max_line_length)
157 std::vector<std::string> result;
158 std::string text = line;
162 if (text.size() <= max_line_length)
164 result.push_back(boost::trim_right_copy(text));
167 std::string::size_type i = text.find_last_of(
" \t", max_line_length);
168 if (i == std::string::npos)
170 result.push_back(text.substr(0, max_line_length));
171 text = text.substr(max_line_length);
175 result.push_back(text.substr(0, i));
176 text = text.substr(i + 1);
188 std::vector<std::string> result;
191 std::vector<std::string> lines =
split(text,
"\n");
192 for (
auto & line : lines)
194 boost::trim_right(line);
198 for (
auto & line : lines)
200 std::vector<std::string> v =
word_wrap_line(line, max_line_length);
201 result.insert(result.end(), v.begin(), v.end());
214 static std::regex re {
"0|(-?[1-9][0-9]*)"};
215 return std::regex_match(s, re);
220 return boost::trim_copy(text);
Standard exception class for reporting runtime errors.
Exception classes for use in libraries and tools.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
static std::vector< std::string > word_wrap_line(const std::string &line, unsigned int max_line_length)
Apply word wrapping to a text that doesn't contain newlines.
std::string string_join(const Container &c, const std::string &separator)
Joins a sequence of strings. This is a replacement for boost::algorithm::join, since it gives stack o...
std::vector< std::string > split_paragraphs(const std::string &text)
Split a string into paragraphs.
void trim(std::string &text)
Remove all trailing and leading spaces from the input.
std::string regex_replace(const std::string &src, const std::string &dest, const std::string &text)
Regular expression replacement in a string.
std::string read_text(const std::string &filename, bool warn=false)
Read text from a file.
std::string word_wrap_text(const std::string &text, unsigned int max_line_length=78)
Apply word wrapping to a text.
bool is_numeric_string(const std::string &s)
Test if a string is a number.
std::vector< std::string > regex_split(const std::string &text, const std::string &sep)
Split a string using a regular expression separator.
std::string remove_comments(const std::string &text)
Remove comments from a text (everything from '' until end of line).
std::string trim_copy(const std::string &text)
Remove all trailing and leading spaces from the input.
std::string remove_whitespace(const std::string &text)
Removes whitespace from a string.
std::vector< std::string > split(const std::string &line, const std::string &separators)
Split the text.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...