CPP-TOOLBOX
Loading...
Searching...
No Matches
text_utils.cpp File Reference
#include "text_utils.hpp"
#include <iostream>
#include <regex>
#include <string>
#include <sstream>
#include <unordered_set>

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::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::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::generate_abbreviation (const std::string &snake_case_name)
 
std::string text_utils::generate_unique_abbreviation (std::unordered_map< std::string, std::string > &current_abbreviation_map, const std::string &word_to_abbreviate)
 
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.
 
std::string text_utils::parse_token (const std::string &s, size_t &pos)
 
Node text_utils::parse_block (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)