Include file:

#include "mcrl2/utilities/text_utility.h"

String manipulation functions.


bool is_numeric_string(const std::string &s)

Test if a string is a number.


  • s A string of text.

Returns: True if s is of the form “0 | -? [1-9][0-9]*”, false otherwise

void mcrl2::utilities::number2string(std::size_t number, std::string &buffer, std::size_t start_position)

Convert a number to a string in the buffer starting at position start_position.


  • number The number to be converted.

  • buffer A buffer in which the string will be stored that is sufficiently large.

  • start_position The first position where a number is written.

std::string mcrl2::utilities::number2string(std::size_t number)

Convert a number to string.

This function is much faster than std::to_string and its use is therefore preferred in those cases were performance counts.


  • number A number to be transformed.

std::string read_text(const std::string &filename, bool warn = false)

Read text from a file.


  • filename A string

  • warn If true, a warning is printed to standard error if the file is not found

Returns: The contents of the file

std::string mcrl2::utilities::read_text(std::istream &in)

Read text from a stream.


  • in An input stream

Returns: The text read from the stream

std::string regex_replace(const std::string &src, const std::string &dest, const std::string &text)

Regular expression replacement in a string.


  • src A string

  • dest A string

  • text A string

Returns: The transformed string

std::vector<std::string> regex_split(const std::string &text, const std::string &sep)

Split a string using a regular expression separator.


  • text A string

  • sep A string

Returns: The splitted string

std::string remove_comments(const std::string &text)

Remove comments from a text (everything from ‘’ until end of line).


  • text A string

Returns: The removal result

std::string remove_whitespace(const std::string &text)

Removes whitespace from a string.


  • text A string

Returns: The removal result

std::vector<std::string> split(const std::string &line, const std::string &separators)

Split the text.


  • line A string

  • separators A string

Returns: The splitted text

std::vector<std::string> split_paragraphs(const std::string &text)

Split a string into paragraphs.


  • text A string

Returns: The paragraphs of text

std::string mcrl2::utilities::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 overflow errors with Visual C++ express 9.0 under some circumstances.

std::string mcrl2::utilities::to_string(const T &x)

Transform parameter into string.


  • x Some expression

Pre: type T has operator <<

Returns: The string representation of x.

void trim(std::string &text)

Remove all trailing and leading spaces from the input.


  • text A string

std::string trim_copy(const std::string &text)

Remove all trailing and leading spaces from the input.


  • text A string

Returns: The trimmed string

std::string word_wrap_text(const std::string &text, unsigned int max_line_length = 78)

Apply word wrapping to a text.


  • text A string of text.

  • max_line_length The maximum line length.

Returns: The wrapped text.