Maze Builder Docs 7.5.6
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 bool contains (const std::string &str, const std::string &substr) noexcept
 Check if a string contains a substring.
 
static std::string get_file_extension (const std::string &filename) noexcept
 Extract file extension from a filename.
 
static bool ends_with (const std::string &str, const std::string &suffix) noexcept
 Check if a string ends with a specific suffix.
 
static bool find (std::string_view sv, char c) noexcept
 Find a character in a string_view.
 
static std::string_view find_first_of (const std::string_view &s, const std::string_view &chars) noexcept
 Find the first occurrence of any character from a set in a string view.
 
static std::string_view strip (const std::string_view &s, const std::string_view &to_strip_from_s=" ") noexcept
 Strip specific characters from the beginning and end of a string view.
 
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 strip_whitespace (const std::string &s)
 Removes consecutive whitespace characters from a string, leaving only single whitespace between non-whitespace characters.
 
template<typename... Args>
static std::string format (std::string_view format_str, const Args &...args) noexcept
 Simple wrapper for fmt::format using runtime format strings (string_view)
 

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()

static 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
The concatenated string

◆ contains()

static bool mazes::string_utils::contains ( const std::string & str,
const std::string & substr )
staticnoexcept

Check if a string contains a substring.

Parameters
strThe string to search in
substrThe substring to search for
Returns
True if substr is found in str, false otherwise

◆ ends_with()

static bool mazes::string_utils::ends_with ( const std::string & str,
const std::string & suffix )
staticnoexcept

Check if a string ends with a specific suffix.

Parameters
strThe string to check
suffixThe suffix to check for
Returns
True if str ends with suffix, false otherwise

◆ find()

static bool mazes::string_utils::find ( std::string_view sv,
char c )
staticnoexcept

Find a character in a string_view.

Parameters
svThe string_view to search in
cThe character to search for
Returns
True if c is found in sv, false otherwise

◆ find_first_of()

static std::string_view mazes::string_utils::find_first_of ( const std::string_view & s,
const std::string_view & chars )
staticnoexcept

Find the first occurrence of any character from a set in a string view.

Parameters
sThe string view to search in
charsThe set of characters to search for
Returns
A string view starting from the first occurrence of any character in chars, or the end of s if none found

◆ format()

template<typename... Args>
static std::string mazes::string_utils::format ( std::string_view format_str,
const Args &... args )
staticnoexcept

Simple wrapper for fmt::format using runtime format strings (string_view)

Template Parameters
ArgsTypes of the arguments to format
Parameters
format_strFormat string as string_view
argsArguments to format
Returns
Formatted string

◆ get_file_extension()

static std::string mazes::string_utils::get_file_extension ( const std::string & filename)
staticnoexcept

Extract file extension from a filename.

Parameters
filenameThe filename to process
Returns
The file extension, excluding the dot, or empty string if no extension

◆ is_whitespace()

template<typename T >
static 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.

◆ split() [1/2]

template<typename It , typename Oc , typename V >
static 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 >
static 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()

static std::string_view mazes::string_utils::strip ( const std::string_view & s,
const std::string_view & to_strip_from_s = " " )
staticnoexcept

Strip specific characters from the beginning and end of a string view.

Parameters
sThe string view to strip characters from
to_strip_from_sThe character to strip
Returns
A new string view with the specified characters removed from both ends

◆ strip_whitespace()

static std::string mazes::string_utils::strip_whitespace ( const std::string & s)
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 >
static 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: