String helper class.
More...
#include <string_utils.h>
|
| 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) |
String helper class.
This class provides common string manipulation utilities ://github.com/PacktPublishing/CPP-20-STL-Cookbook/blob/main/chap11/split.cpp
◆ concat()
| std::string mazes::string_utils::concat |
( |
const std::string & | a, |
|
|
const std::string & | b ) |
|
staticnoexcept |
Combine and return two strings.
- Parameters
-
| a | The first string |
| b | The 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
-
| T | The type of the character to check. |
- Parameters
-
| c | The 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
-
| pattern | The 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
-
| It | Iterator type |
| Oc | Output container type |
| V | Value type |
- Parameters
-
| it | Start iterator |
| end_it | End iterator |
| dest | Output container |
| sep | Separator 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
-
| It | Type of the iterator for the input range. |
| Oc | Type of the output container that will store the slices. |
| V | Type of the separator value. |
| Pred | Type of the predicate function used to compare elements to the separator. |
- Parameters
-
| it | Iterator pointing to the beginning of the range to split. |
| end_it | Iterator pointing to the end of the range to split. |
| dest | Destination container where the resulting slices will be stored. |
| sep | Separator value used to determine where to split the range. |
| f | Predicate 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
-
| s | The 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
-
| Cin | Input container type |
| Cout | Output container type |
| V | Value type |
- Parameters
-
| str | Input container/string |
| dest | Output container |
| sep | Separator value |
- Returns
- Reference to output container
The documentation for this class was generated from the following file: