Implementation of string utility functions.
Definition in file string.cpp.
#include "genesis/utils/text/string.hpp"
#include "genesis/utils/math/common.hpp"
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <stdexcept>
Go to the source code of this file.
Namespaces | |
genesis | |
Container namespace for all symbols of genesis in order to keep them separate when used as a library. | |
genesis::utils | |
Functions | |
int | compare_natural (std::string const &lhs, std::string const &rhs) |
Compare two strings with natural human sorting, that is "A1", "A2", "A100", instead of the standard sort by ASCII value "A1", "A100", "A2". More... | |
bool | contains_ci (std::vector< std::string > const &haystack, std::string const &needle) |
Return whether a vector of strings contains a given string, case insensitive. More... | |
size_t | count_substring_occurrences (std::string const &str, std::string const &sub) |
Return the number of (possibly overlapping) occurrences of a substring in a string. More... | |
char | deescape (char c) |
Return the de-escaped char for a backslash-escaped char. More... | |
std::string | deescape (std::string const &text) |
Return a string where backslash-escaped characters are transformed into their respective string form. More... | |
bool | ends_with (std::string const &text, std::string const &ending) |
Return whether a string ends with another string. More... | |
bool | equals_ci (std::string const &lhs, std::string const &rhs) |
Compare two strings case insensitive. More... | |
std::string | escape (std::string const &text) |
Return a string where special chars are replaces by their escape sequence. More... | |
std::string | head (std::string const &text, size_t lines=10) |
Return the first lines of the text. More... | |
std::string | indent (std::string const &text, std::string const &indentation=" ") |
Indent each line of text with indentation and return the result. More... | |
bool | match_wildcards (std::string const &str, std::string const &pattern) |
Return whether a string is matched by a wildcard pattern containing ? and * for single and mutliple (0 or more) wildcard characters, respectively. More... | |
std::string | repeat (std::string const &word, size_t times) |
Take a string and repeat it a given number of times. More... | |
std::string | replace_all (std::string const &text, std::string const &search, std::string const &replace) |
Return a copy of a string, where all occurrences of a search string are replaced by a replace string. More... | |
std::string | replace_all_chars (std::string const &text, std::string const &search_chars, char replace) |
Replace all occurrences of the search_chars in text by the replace char. More... | |
std::vector< std::string > | split (std::string const &str, std::function< bool(char)> delimiter_predicate, const bool trim_empty=true) |
Spilt a string into parts, given a delimiter_predicate that returns true for delimiters chars. More... | |
std::vector< std::string > | split (std::string const &str, std::string const &delimiters=" ", const bool trim_empty=true) |
Spilt a string into parts, given a delimiters set of chars. More... | |
static std::vector< std::string > | split_ (std::string const &string, std::function< size_t(std::string const &, size_t)> find_pos, size_t advance_by, const bool trim_empty) |
Local function that does the work for the split cuntions. More... | |
std::vector< std::string > | split_at (std::string const &str, std::string const &delimiter, const bool trim_empty=true) |
Spilt a string into parts, given a delimiter string. More... | |
std::vector< size_t > | split_range_list (std::string const &str) |
Split a string containing positive interger numbers into its parts and resolve ranges. More... | |
bool | starts_with (std::string const &text, std::string const &start) |
Return whether a string starts with another string. More... | |
std::string | tail (std::string const &text, size_t lines=10) |
Return the last lines of the text. More... | |
std::string | to_lower_ascii (std::string const &str) |
Return an all-lowercase copy of the given string, ASCII-only. More... | |
void | to_lower_ascii_inplace (std::string &str) |
Turn the given string to all-lowercase, ASCII-only. More... | |
std::string | to_string_leading_zeros (size_t value, size_t length=6) |
Return a string representation of a size_t value with a fixed length, that is, by adding leading zeros. More... | |
std::string | to_string_precise (double value, int precision=6) |
Return a precise string representation of the input value, using the provided precision value (determining its decimal places). More... | |
std::string | to_string_rounded (double value, int precision=6) |
Return a string representation of the input value, using the provided precision value (determining its decimal places) to round, and truncate trailing zeros. More... | |
std::string | to_upper_ascii (std::string const &str) |
Return an all-uppercase copy of the given string, ASCII-only. More... | |
void | to_upper_ascii_inplace (std::string &str) |
Turn the given string to all-uppercase, ASCII-only, inline. More... | |
std::string | trim (std::string const &s, std::string const &delimiters=" \f\n\r\t\v") |
Return a copy of the input string, with trimmed white spaces. More... | |
std::string | trim_left (std::string const &s, std::string const &delimiters=" \f\n\r\t\v") |
Return a copy of the input string, with right trimmed white spaces. More... | |
std::string | trim_right (std::string const &s, std::string const &delimiters=" \f\n\r\t\v") |
Return a copy of the input string, with left trimmed white spaces. More... | |
std::string | wrap (std::string const &text, size_t line_length=80) |
Wrap a text at a given line_length . More... | |