Maze Builder Docs 8.10.23
Loading...
Searching...
No Matches
mazes::string_utils Class Reference

String helper class. More...

#include <string_utils.h>

Static Public Member Functions

static std::string concat (const std::string &a, const std::string &b) noexcept
 Combine and return two strings.
static std::string make_mask_source (const std::string &pattern) noexcept
 Generate a mask string based on the given pattern.
template<typename It, typename Oc, typename V, typename Pred>
static It split (It it, const It end_it, Oc &dest, const V &sep, Pred f)
 Splits a range into slices based on a separator and stores the results in a destination container.
template<typename It, typename Oc, typename V>
static It split (It it, const It end_it, Oc &dest, const V &sep)
 Generic split function with default equality predicate.
template<typename Cin, typename Cout, typename V>
static Cout & strsplit (const Cin &str, Cout &dest, const V &sep)
 High-level string split function using containers.
template<typename T>
static bool is_whitespace (const T &c)
 Checks if a character is a whitespace character.
static std::string_view strip_whitespace (std::string_view sv)
 Removes consecutive whitespace characters from a string, leaving only single whitespace between non-whitespace characters.
static std::string_view strip_backticks (std::string_view sv)
static std::string_view strip_quotes (std::string_view sv)
static std::string replace_all (const std::string &s, const std::string &from, const std::string &to)

Detailed Description

String helper class.

This class provides common string manipulation utilities ://github.com/PacktPublishing/CPP-20-STL-Cookbook/blob/main/chap11/split.cpp

Member Function Documentation

◆ concat()

std::string mazes::string_utils::concat ( const std::string & a,
const std::string & b )
staticnoexcept

Combine and return two strings.

Parameters
aThe first string
bThe second string
Returns
A representation of the concatenated string

◆ is_whitespace()

template<typename T>
bool mazes::string_utils::is_whitespace ( const T & c)
inlinestatic

Checks if a character is a whitespace character.

Template Parameters
TThe type of the character to check.
Parameters
cThe character to check for whitespace.
Returns
True if the character is a whitespace character; otherwise, false.

◆ make_mask_source()

std::string mazes::string_utils::make_mask_source ( const std::string & pattern)
staticnoexcept

Generate a mask string based on the given pattern.

Parameters
patternThe pattern string used to create the mask.
Returns
A string representing the generated mask.

◆ split() [1/2]

template<typename It, typename Oc, typename V>
It mazes::string_utils::split ( It it,
const It end_it,
Oc & dest,
const V & sep )
inlinestatic

Generic split function with default equality predicate.

Template Parameters
ItIterator type
OcOutput container type
VValue type
Parameters
itStart iterator
end_itEnd iterator
destOutput container
sepSeparator value
Returns
Iterator to end position

◆ split() [2/2]

template<typename It, typename Oc, typename V, typename Pred>
It mazes::string_utils::split ( It it,
const It end_it,
Oc & dest,
const V & sep,
Pred f )
inlinestatic

Splits a range into slices based on a separator and stores the results in a destination container.

Template Parameters
ItType of the iterator for the input range.
OcType of the output container that will store the slices.
VType of the separator value.
PredType of the predicate function used to compare elements to the separator.
Parameters
itIterator pointing to the beginning of the range to split.
end_itIterator pointing to the end of the range to split.
destDestination container where the resulting slices will be stored.
sepSeparator value used to determine where to split the range.
fPredicate function that determines if an element matches the separator.
Returns
Iterator pointing to the position after the last processed element, or end_it if the entire range was processed.

◆ strip_whitespace()

std::string_view mazes::string_utils::strip_whitespace ( std::string_view sv)
inlinestatic

Removes consecutive whitespace characters from a string, leaving only single whitespace between non-whitespace characters.

Parameters
sThe input string from which to strip consecutive whitespace.
Returns
A new string with consecutive whitespace characters replaced by a single whitespace.

◆ strsplit()

template<typename Cin, typename Cout, typename V>
Cout & mazes::string_utils::strsplit ( const Cin & str,
Cout & dest,
const V & sep )
inlinestatic

High-level string split function using containers.

Template Parameters
CinInput container type
CoutOutput container type
VValue type
Parameters
strInput container/string
destOutput container
sepSeparator value
Returns
Reference to output container

The documentation for this class was generated from the following file: