14#include <boost/algorithm/string.hpp>
15#include "mcrl2/utilities/exception.h"
16#include "mcrl2/utilities/logger.h"
27std::vector<std::string> split_paragraphs(
const std::string& text)
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());
78 throw mcrl2::
runtime_error(
"Could not open input file: " + filename);
81 in.unsetf(std::ios::skipws);
85 std::istream_iterator<
char>(in),
86 std::istream_iterator<
char>(),
96std::string remove_comments(
const std::string& text)
99 std::regex src {
"%[^\\n]*\\n"};
101 std::string dest(
"\n");
102 return std::regex_replace(text, src, dest);
108std::string remove_whitespace(
const std::string& text)
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);
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);
186std::string word_wrap_text(
const std::string& text,
unsigned int max_line_length)
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());
204 return string_join(result,
"\n");
210bool is_numeric_string(
const std::string& s)
214 static std::regex re {
"0|(-?[1-9][0-9]*)"};
215 return std::regex_match(s, re);
218std::string trim_copy(
const std::string& text)
220 return boost::trim_copy(text);
223void trim(
std::string& text)
logger(const log_level_t l)
Default constructor.
Standard exception class for reporting runtime errors.
#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.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const