SlHelpers
Loading...
Searching...
No Matches
SlHelpers::String Class Reference

Various helpers on strings. More...

#include <String.h>

Classes

struct  Hash
 Hash for string and string_view to be used in hashing containers. More...
struct  Eq
 Equality test for string and string_view to be used in containers. More...

Static Public Member Functions

template<typename I = unsigned>
requires std::is_integral_v<I>
static std::optional< I > toNum (std::string_view str, int base=10) noexcept
 Convert str to a number.
static bool constexpr iEqual (unsigned char a, unsigned char b) noexcept
 Compare two characters ignoring case.
static constexpr std::string_view::size_type iFind (std::string_view str, std::string_view sub) noexcept
 Like string::find() but ignoring case.
static constexpr bool iStartsWith (std::string_view str, std::string_view prefix) noexcept
 Like string::starts_with() but ignoring case.
static constexpr bool iEndsWith (std::string_view str, std::string_view suffix) noexcept
 Like string::ends_with() but ignoring case.
static std::vector< std::string_view > splitSV (std::string_view str, std::string_view delim, std::optional< char > comment=std::nullopt) noexcept
 Split str by delim into a vector, ignoring everything after comment.
template<typename T>
static constexpr T trim (const T &line) noexcept
 Trim string (remove surrounding whitespace).
static constexpr bool isHex (std::string_view s) noexcept
 Is the string consisting of hex number?
template<std::ranges::input_range Range, typename Output>
requires requires(std::ostream &out, Output output, std::ranges::range_reference_t<Range> e) { std::invoke(output, out, e); }
static void join (std::ostream &out, Range &&iterable, Output output, std::string_view sep=", ")
 Join iterable into out using separator sep, calling output.
template<std::ranges::input_range Range>
static void join (std::ostream &out, Range &&iterable, std::string_view sep=", ", std::string_view quote="")
 Join iterable into out using separator sep and quoting quote.

Static Public Attributes

static constinit const auto npos = std::string_view::npos
 A local alias for std::string_view::npos.

Detailed Description

Various helpers on strings.

Member Function Documentation

◆ iEndsWith()

constexpr bool SlHelpers::String::iEndsWith ( std::string_view str,
std::string_view suffix )
inlinestaticconstexprnoexcept

Like string::ends_with() but ignoring case.

Parameters
strstring to search in
suffixstring to search for
Returns
true if str ends with suffix, false otherwise

◆ iFind()

constexpr std::string_view::size_type SlHelpers::String::iFind ( std::string_view str,
std::string_view sub )
inlinestaticconstexprnoexcept

Like string::find() but ignoring case.

Parameters
strstring to search in
substring to search for
Returns
position of sub in str if found, npos otherwise

◆ isHex()

constexpr bool SlHelpers::String::isHex ( std::string_view s)
inlinestaticconstexprnoexcept

Is the string consisting of hex number?

Parameters
sString to inspect
Returns
true if all characters are hex numbers

◆ iStartsWith()

constexpr bool SlHelpers::String::iStartsWith ( std::string_view str,
std::string_view prefix )
inlinestaticconstexprnoexcept

Like string::starts_with() but ignoring case.

Parameters
strstring to search in
prefixstring to search for
Returns
true if str starts with prefix, false otherwise

◆ join() [1/2]

template<std::ranges::input_range Range, typename Output>
requires requires(std::ostream &out, Output output, std::ranges::range_reference_t<Range> e) { std::invoke(output, out, e); }
void SlHelpers::String::join ( std::ostream & out,
Range && iterable,
Output output,
std::string_view sep = ", " )
inlinestatic

Join iterable into out using separator sep, calling output.

Parameters
outOutput stream
iterableInput container
outputCalled for every member; it should output the member to out
sepSeparator

◆ join() [2/2]

template<std::ranges::input_range Range>
void SlHelpers::String::join ( std::ostream & out,
Range && iterable,
std::string_view sep = ", ",
std::string_view quote = "" )
inlinestatic

Join iterable into out using separator sep and quoting quote.

Parameters
outOutput stream
iterableInput container
sepSeparator
quoteQuoting string, it is put before and after each value in iterable

◆ splitSV()

std::vector< std::string_view > SlHelpers::String::splitSV ( std::string_view str,
std::string_view delim,
std::optional< char > comment = std::nullopt )
inlinestaticnoexcept

Split str by delim into a vector, ignoring everything after comment.

Parameters
strString to parse
delimDelimeter to split by
commentIgnore string after character
Returns
Vector built of str.

Note str must outlive the use of the return value!

◆ trim()

template<typename T>
constexpr T SlHelpers::String::trim ( const T & line)
inlinestaticconstexprnoexcept

Trim string (remove surrounding whitespace).

Parameters
lineString to trim
Returns
Trimmed string.

The documentation for this class was generated from the following file:
  • /home/abuild/rpmbuild/BUILD/slhelpers-20260626.4928fc7-build/slhelpers-20260626.4928fc7/include/helpers/String.h