CPP-TOOLBOX
Loading...
Searching...
No Matches
text_utils.hpp File Reference
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>
#include <stdexcept>

Go to the source code of this file.

Classes

class  text_utils::StringAccumulator
 
class  text_utils::MultilineStringAccumulator
 
struct  text_utils::Node
 

Namespaces

namespace  text_utils
 

Functions

std::string text_utils::remove_consecutive_duplicates (const std::string &input, const std::string &dedup_chars="")
 Remove consecutive duplicate characters from a string.
 
std::string text_utils::abbreviate_snake_case (const std::string &input)
 Abbreviate a snake_case string by shortening each word.
 
bool text_utils::is_integer (const std::string &str)
 Check if a string represents an integer.
 
bool text_utils::is_rational (const std::string &str)
 Check if a string represents a rational (floating-point) number.
 
std::string text_utils::add_newlines_to_long_string (const std::string &text, size_t max_chars_per_line=25)
 Insert newlines into long strings.
 
std::vector< std::string > text_utils::split (const std::string &str, const std::string &delimiter)
 Split a string by a delimiter.
 
std::vector< std::string > text_utils::split_once_from_right (const std::string &str, const std::string &delimiter)
 Split a string once from the right.
 
std::string text_utils::join (const std::vector< std::string > &elements, const std::string &separator)
 Join elements into a single string with a separator.
 
std::string text_utils::trim (const std::string &s)
 Trim whitespace from both ends of a string.
 
std::string text_utils::surround (const std::string &str, const std::string &left, const std::string &right="")
 Surround a string with left and right substrings.
 
std::string text_utils::pascal_to_snake_case (const std::string &input)
 Convert a PascalCase string to snake_case.
 
std::string text_utils::snake_to_pascal_case (const std::string &input)
 Convert a snake_case string to PascalCase.
 
std::string text_utils::join_multiline (const std::string &input, bool replace_newlines_with_space=false)
 Join a string with newlines removed or replaced.
 
std::string text_utils::replace_char (const std::string &input, char from_char, char to_char)
 Replace a character with another in a string.
 
std::string text_utils::replace_chars (const std::string &input, const std::unordered_map< char, char > &mapping)
 Replace characters in a string according to a mapping.
 
std::string text_utils::replace_substring (const std::string &input, const std::string &from_substr, const std::string &to_substr)
 Replace all occurrences of a substring with another substring.
 
bool text_utils::starts_with (const std::string &str, const std::string &prefix)
 Check if a string starts with a prefix.
 
bool text_utils::contains (const std::string &str, const std::string &substr)
 Check if a string contains a substring.
 
std::string text_utils::get_substring (const std::string &input, size_t start, size_t end)
 Extract a substring from start to end indices.
 
std::string text_utils::remove_newlines (const std::string &input)
 Remove all newlines from a string.
 
std::string text_utils::collapse_whitespace (const std::string &input)
 Collapse consecutive whitespace into a single space.
 
std::string text_utils::replace_literal_newlines_with_real (const std::string &input)
 Replace literal "\n" sequences with real newlines.
 
std::string text_utils::indent (const std::string &text, int indent_level, int spaces_per_indent=4)
 Indent text by a given number of levels.
 
std::unordered_map< std::string, std::string > text_utils::map_words_to_abbreviations (const std::vector< std::string > &words)
 Create a map from words to their abbreviations.
 
Node text_utils::parse_block (const std::string &s, size_t &pos)
 
std::string text_utils::parse_token (const std::string &s, size_t &pos)
 
std::vector< std::string > text_utils::build_buffer (const Node &node)
 
std::string text_utils::format_nested_brace_string_recursive (const std::string &input)
 

Variables

const std::string text_utils::double_quote = "\""
 
const std::string text_utils::single_quote = "'"
 
const std::string text_utils::newline = "\n"
 
const std::string text_utils::tab = "\t"
 
const std::string text_utils::space = " "
 
const std::string text_utils::empty = ""
 
const std::string text_utils::comma = ","
 
const std::string text_utils::period = "."
 
const std::string text_utils::colon = ":"
 
const std::string text_utils::semicolon = ";"
 
const std::string text_utils::dash = "-"
 
const std::string text_utils::underscore = "_"
 
const std::string text_utils::slash = "/"
 
const std::string text_utils::backslash = "\\"
 
const std::string text_utils::pipe = "|"
 
const std::string text_utils::ampersand = "&"
 
const std::string text_utils::at_sign = "@"
 
const std::string text_utils::hash = "#"
 
const std::string text_utils::dollar = "$"
 
const std::string text_utils::percent = "%"
 
const std::string text_utils::caret = "^"
 
const std::string text_utils::asterisk = "*"
 
const std::string text_utils::plus = "+"
 
const std::string text_utils::equals = "="
 
const std::string text_utils::question_mark = "?"
 
const std::string text_utils::exclamation_mark = "!"
 
const std::string text_utils::left_paren = "("
 
const std::string text_utils::right_paren = ")"
 
const std::string text_utils::left_bracket = "["
 
const std::string text_utils::right_bracket = "]"
 
const std::string text_utils::left_brace = "{"
 
const std::string text_utils::right_brace = "}"
 
const std::string text_utils::less_than = "<"
 
const std::string text_utils::greater_than = ">"
 
const std::string text_utils::newline_windows = "\r\n"
 
const std::string text_utils::carriage_return = "\r"
 
const std::string text_utils::natural_numbers = "ℕ"
 
const std::string text_utils::element_of = "∈"