Static Public Member Functions | List of all members
Strings Struct Referencefinal

Utilities for strings. More...

#include <Strings.hpp>

Static Public Member Functions

static void append (std::string &str, char c, size_t count)
 Appends count times the supplied ascii character to the supplied UTF-8 string (in place version). More...
 
static void append (std::string &str, char32_t c, size_t count)
 Appends count times the supplied code point to the supplied UTF-8 string (in place version). More...
 
static void append (std::u32string &str, char32_t c, size_t count)
 Appends count times the supplied code point to the supplied UTF-32 string (in place version). More...
 
static std::string append (const std::string_view &str, char c, size_t count)
 Returns the supplied UTF-8 string with count times the supplied ascii character appended to it. More...
 
static std::string append (const std::string &str, char32_t c, size_t count)
 Returns the supplied UTF-8 string with count times the supplied code point appended to it. More...
 
static std::u32string append (const std::u32string &str, char32_t c, size_t count)
 Returns the supplied UTF-32 string with count times the supplied code point appended to it. More...
 
static size_t codePointCount (const std::string_view &str)
 Count the number of code points in the supplied UTF-8 string. More...
 
static size_t codePointCount (const std::u32string_view &str)
 Count the number of code points in the supplied UTF-32 string. More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT, typename SubstrT >
static bool contains (const StringT< CharT, T ... > &str, const SubstrT &substring)
 Does the first string contain the second string? More...
 
template<typename CharT , typename SubstrT >
static bool contains (const CharT *str, const SubstrT &substring)
 Does the first string contain the second string? More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT>
static bool contains (const StringT< CharT, T ... > &str, const CharT &c)
 Does the string contain the ascii char (UTF-8) / UTF-16 char (UTF-16) / code point (UTF-32)? More...
 
template<typename CharT >
static bool contains (const CharT *str, const CharT &c)
 Does the string contain the ascii char (UTF-8) / UTF-16 char (UTF-16) / code point (UTF-32)? More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT, typename SuffixT >
static bool endsWith (const StringT< CharT, T ... > &str, const SuffixT &suffix)
 Does the string end with the specified suffix? More...
 
template<typename CharT , typename SuffixT >
static bool endsWith (const CharT *str, const SuffixT &suffix)
 Does the string end with the specified suffix? More...
 
template<typename CharT >
static bool endsWith (const std::basic_string_view< CharT > &str, const std::basic_string_view< CharT > &suffix)
 Does the first string end with the specified suffix? More...
 
static bool endsWith (const char *str, const char suffix)
 Does the UTF-8 string end with the specified ascii char? More...
 
static bool endsWith (const std::string_view &str, const char suffix)
 Does the UTF-8 string end with the specified ascii char? More...
 
static bool endsWith (const char32_t *str, const char32_t suffix)
 Does the UTF-32 string end with the specified ascii char? More...
 
static bool endsWith (const std::u32string_view &str, const char32_t suffix)
 Does the UTF-32 string end with the specified code point? More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT, typename SubstrT >
static bool equalsIgnoreCase (const StringT< CharT, T ... > &lhs, const SubstrT &rhs)
 Ignoring case, is the first string equal to the second string? More...
 
template<typename CharT , typename SubstrT >
static bool equalsIgnoreCase (const CharT *lhs, const SubstrT &rhs)
 Ignoring case, is the first string equal to the second string? More...
 
template<typename AllocatorT , typename CharT , typename ... T, template< typename ... > class StringT, typename P1 , typename ... P>
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > join (StringT< CharT, T ... > delimiter, const P1 &p1, const P &... p)
 Call to-string on each of the objects and join the resulting strings together with the delimiter. More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT, typename P1 , typename ... P>
static std::basic_string< CharT > join (StringT< CharT, T ... > delimiter, const P1 &p1, const P &... p)
 Call to-string on each of the objects and join the resulting strings together with the delimiter. More...
 
template<typename AllocatorT , typename CharT , typename P1 , typename ... P>
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > join (const CharT *delimiter, const P1 &p1, const P &... p)
 Call to-string on each of the objects and join the resulting strings together with the delimiter. More...
 
template<typename CharT , typename P1 , typename ... P>
static std::basic_string< CharT > join (const CharT *delimiter, const P1 &p1, const P &... p)
 Call to-string on each of the objects and join the resulting strings together with the delimiter. More...
 
template<typename AllocatorT , typename CharT , typename ... T, template< typename ... > class C>
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > joinContainer (const CharT *delimiter, const C< T ... > &container)
 Call to-string on each of the objects in the container and join the resulting strings together with the delimiter. More...
 
template<typename CharT , typename ... T, template< typename ... > class C>
static std::basic_string< CharT > joinContainer (const CharT *delimiter, const C< T ... > &container)
 Call to-string on each of the objects in the container and join the resulting strings together with the delimiter. More...
 
template<typename AllocatorT , typename CharT , typename ... T, template< typename ... > class C>
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > joinContainer (const std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > &delimiter, const C< T ... > &container)
 Call to-string on each of the objects in the container and join the resulting strings together with the delimiter. More...
 
template<typename CharT , typename ... T, template< typename ... > class C>
static std::basic_string< CharT > joinContainer (const std::basic_string< CharT > &delimiter, const C< T ... > &container)
 Call to-string on each of the objects in the container and join the resulting strings together with the delimiter. More...
 
template<typename AllocatorT , typename CharT , typename ... T, template< typename ... > class C>
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > joinContainer (std::basic_string_view< CharT > delimiter, const C< T ... > &container)
 Call to-string on each of the objects in the container and join the resulting strings together with the delimiter. More...
 
template<typename CharT , typename ... T, template< typename ... > class C>
static std::basic_string< CharT > joinContainer (std::basic_string_view< CharT > delimiter, const C< T ... > &container)
 Call to-string on each of the objects in the container and join the resulting strings together with the delimiter. More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT, typename SubstrT >
static size_t lastIndexOf (const StringT< CharT, T ... > &str, const SubstrT &substring)
 Get the character (UTF-8) / code point (UTF-32) position of the last index of the specified sub-string. More...
 
template<typename CharT , typename SubstrT >
static size_t lastIndexOf (const CharT *str, const SubstrT &substring)
 Get the character (UTF-8) / code point (UTF-32) position of the last index of the specified sub-string. More...
 
template<typename ... T, template< typename ... > class StringT>
static std::vector< size_t > lineLengths (const StringT< char, T ... > &text, const std::regex &lineBreakRegex, bool includeExtraTextAsLine=true)
 Determine the lengths of the lines in bytes, given the line break regular expression. More...
 
template<typename ... T, template< typename ... > class StringT>
static std::vector< size_t > lineLengths (const StringT< char, T ... > &text, bool includeExtraTextAsLine=true)
 Given the supplied multi-line text string, determine the length of each line in bytes. More...
 
static std::vector< size_t > lineLengths (const char *text, bool includeExtraTextAsLine=true)
 Given the supplied multi-line text string, determine the length of each line in bytes. More...
 
static bool matches (const std::string &str, const std::regex &re)
 Does the string match the specified regular expression? More...
 
template<typename CharT , typename SubstrT >
static size_t occurrences (const CharT *str, const SubstrT &substring)
 How many non-overlapping occurrences of the second string are found in the first string? More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT, typename SubstrT >
static size_t occurrences (const StringT< CharT, T ... > &str, const SubstrT &substring)
 How many non-overlapping occurrences of the second string are found in the first string? More...
 
static size_t occurrences (const std::string &str, const std::regex &regex)
 Count the number of non-overlapping occurrences of the supplied regular expression. More...
 
static size_t occurrences (const char *str, const std::regex &regex)
 Count the number of non-overlapping occurrences of the supplied regular expression. More...
 
static size_t occurrences (const std::string_view &str, const std::regex &regex)
 Count the number of non-overlapping occurrences of the supplied regular expression. More...
 
static std::string padLeft (const std::string_view &str, unsigned int width, char c=' ')
 Left pad the supplied UTF-8 string up to the specified width in code points. More...
 
static std::string padLeft (const std::string_view &str, unsigned int width, char32_t c)
 Left pad the supplied UTF-8 string up to the specified width in code points. More...
 
static std::u32string padLeft (const std::u32string_view &str, unsigned int width, char32_t c=U' ')
 Left pad the supplied UTF-32 string up to the specified width in code points. More...
 
static std::string padRight (const std::string_view &str, unsigned int width, char c=' ')
 Right pad the supplied UTF-8 string up to the specified width in code points. More...
 
static std::string padRight (const std::string_view &str, unsigned int width, char32_t c)
 Right pad the supplied UTF-8 string up to the specified width in code points. More...
 
static std::u32string padRight (const std::u32string_view &str, unsigned int width, char32_t c=U' ')
 Right pad the supplied UTF-32 string up to the specified width in code points. More...
 
template<typename AllocatorT , typename CharT , typename ... T, template< typename ... > class C, typename ... U, template< typename ... > class PrefixT, typename ... V, template< typename ... > class SuffixT>
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > prefixSuffixJoin (const C< T ... > &container, const PrefixT< CharT, U ... > &prefix, const SuffixT< CharT, V ... > &suffix)
 Call to-string on each of the objects in the container and join the resulting strings together with the prefix and suffix. More...
 
template<typename CharT , typename ... T, template< typename ... > class C, typename ... U, template< typename ... > class PrefixT, typename ... V, template< typename ... > class SuffixT>
static std::string prefixSuffixJoin (const C< T ... > &container, const PrefixT< CharT, U ... > &prefix, const SuffixT< CharT, V ... > &suffix)
 Call to-string on each of the objects in the container and join the resulting strings together with the prefix and suffix. More...
 
template<typename AllocatorT , typename CharT , typename ... T, template< typename ... > class C>
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > prefixSuffixJoin (const C< T ... > &container, const CharT *prefix, const CharT *suffix)
 Call to-string on each of the objects in the container and join the resulting strings together with the prefix and suffix. More...
 
template<typename CharT , typename ... T, template< typename ... > class C>
static std::basic_string< CharT > prefixSuffixJoin (const C< T ... > &container, const CharT *prefix, const CharT *suffix)
 Call to-string on each of the objects in the container and join the resulting strings together with the prefix and suffix. More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT, typename MatchT , typename ReplacementT >
static std::basic_string< CharT > replaceAll (const StringT< CharT, T ... > &input, const MatchT &match, const ReplacementT &replacement)
 Replace all occurrences of the specified string with the supplied replacement. More...
 
template<typename CharT , typename AllocatorT , typename ... T, template< typename ... > class StringT, typename MatchT , typename ReplacementT >
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > replaceAll (const StringT< CharT, T ... > &input, const MatchT &match, const ReplacementT &replacement)
 Replace all occurrences of the specified string with the supplied replacement (specified allocator version). More...
 
template<typename CharT , typename AllocatorT , typename MatchT , typename ReplacementT >
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > replaceAll (const CharT *input, const MatchT &match, const ReplacementT &replacement)
 Replace all occurrences of the specified string with the supplied replacement. More...
 
template<typename CharT , typename AllocatorT >
static std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > replaceAll (std::basic_string_view< CharT > input, std::basic_string_view< CharT > match, std::basic_string_view< CharT > replacement, size_t *count=nullptr)
 Replace all occurrences of the specified string with the supplied replacement. More...
 
template<typename CharT >
static std::basic_string< CharT > replaceAll (std::basic_string_view< CharT > input, std::basic_string_view< CharT > match, std::basic_string_view< CharT > replacement, size_t *count=nullptr)
 Replace all occurrences of the specified string with the supplied replacement. More...
 
static std::string replaceAll (std::string_view input, std::string_view match, std::string_view replacement, size_t *count=nullptr)
 Replace all occurrences of the specified string with the supplied replacement. More...
 
static std::u32string replaceAll (std::u32string_view input, std::u32string_view match, std::u32string_view replacement, size_t *count=nullptr)
 Replace all occurrences of the specified string with the supplied replacement. More...
 
template<typename ReplacementT >
static std::string replaceAll (const char *input, const std::regex &regex, const ReplacementT &replacement)
 Replace all occurrences of the regular expression in the input string with the replacement string. More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT, typename ReplacementT >
static std::string replaceAll (const StringT< CharT, T ... > &input, const std::regex &regex, const ReplacementT &replacement)
 Replace all occurrences of the regular expression in the input string with the replacement string. More...
 
static std::string simplify (const std::string_view &input)
 Simplify whitespace (conflate blanks) from the supplied UTF-8 string. More...
 
static std::vector< std::string_view > split (const std::string_view &input, const std::regex &delimiter, bool returnDelimiters=false, bool compress=true)
 Split the input string on each of the occurrences of the specified delimiter regular expression. More...
 
static std::vector< std::string_view > split (const std::string_view &input, const std::string_view &delimiter, bool compress=true)
 Split the input string on each of the occurrences of the specified delimiter. More...
 
static std::vector< std::u32string_view > split (const std::u32string_view &input, const std::u32string_view &delimiter, bool compress=true)
 Split the input string on each of the occurrences of the specified delimiter. More...
 
static std::vector< std::string_view > splitAndTrim (const std::string_view &input, const std::regex &delimiter, bool returnDelimiters=false, bool compress=true)
 Split the input string on each of the occurrences of the specified delimiter regular expression and subsequently trim the resulting strings. More...
 
static std::vector< std::string_view > splitAndTrim (const std::string_view &input, const std::string_view &delimiter, bool compress=true)
 Split the input string on each of the occurrences of the specified delimiter and subsequently trim the resulting strings. More...
 
static std::vector< std::u32string_view > splitAndTrim (const std::u32string_view &input, const std::u32string_view &delimiter, bool compress=true)
 Split the input string on each of the occurrences of the specified delimiter and subsequently trim the resulting strings. More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT, typename PrefixT >
static bool startsWith (const StringT< CharT, T ... > &str, const PrefixT &prefix)
 Does the string start with the specified prefix? More...
 
template<typename CharT , typename ... T, template< typename ... > class StringT>
static bool startsWith (const StringT< CharT, T ... > &str, CharT prefix)
 Does the string start with the specified prefix? More...
 
template<typename CharT , typename PrefixT >
static bool startsWith (const CharT *str, const PrefixT &prefix)
 Does the string start with the specified prefix? More...
 
template<typename CharT >
static bool startsWith (const CharT *str, CharT prefix)
 Does the string start with the specified prefix? More...
 
template<typename CharT >
static bool startsWith (const std::basic_string_view< CharT > &str, const std::basic_string_view< CharT > &prefix)
 Does the string start with the specified prefix? More...
 
template<typename CharT >
static bool startsWith (const std::basic_string_view< CharT > &str, CharT prefix)
 Does the string start with the specified prefix? More...
 
static bool startsWithRegex (const std::string &str, const std::regex &prefix)
 Does the string start with the specified regular expression? More...
 
static std::string toLower (const std::string_view &s)
 Convert the supplied UTF-8 string to lowercase. More...
 
static std::u32string toLower (const std::u32string_view &s)
 Convert the supplied UTF-32 string to lowercase. More...
 
template<typename CharT , typename ... T, template< typename ... > class ContainerT>
static ContainerT< std::basic_string< CharT > > toStringContainer (const ContainerT< std::basic_string_view< CharT >, T ... > &input)
 Convert the container of string views to a container of strings. More...
 
static std::string toUpper (const std::string_view &s)
 Convert the supplied UTF-8 string to uppercase. More...
 
static std::u32string toUpper (const std::u32string_view &s)
 Convert the supplied UTF-32 string to uppercase. More...
 
static std::string_view trim (const std::string_view &input)
 Trim whitespace from the beginning and end of the supplied UTF-8 string. More...
 
static std::u32string_view trim (const std::u32string_view &input)
 Trim whitespace from the beginning and end of the supplied UTF-32 string. More...
 
static std::string_view trimLeft (const std::string_view &input)
 Trim whitespace from the beginning of the supplied UTF-8 string. More...
 
static std::u32string_view trimLeft (const std::u32string_view &input)
 Trim whitespace from the beginning of the supplied UTF-32 string. More...
 
static std::string_view trimRight (const std::string_view &input)
 Trim whitespace from the end of the supplied UTF-8 string. More...
 
static std::u32string_view trimRight (const std::u32string_view &input)
 Trim whitespace from the end of the supplied UTF-32 string. More...
 

Detailed Description

Utilities for strings.

The utilities use and return std::string_view objects where possible.

In order to support multiple string types, a two stage typename deduction / type conversion approach is used for many of the functions.

Member Function Documentation

◆ append() [1/6]

static void append ( std::string &  str,
char  c,
size_t  count 
)
inlinestatic

Appends count times the supplied ascii character to the supplied UTF-8 string (in place version).

Parameters
strthe UTF-8 string to append in place
cthe ascii character
countthe number of times to append the ascii character

◆ append() [2/6]

static void append ( std::string &  str,
char32_t  c,
size_t  count 
)
inlinestatic

Appends count times the supplied code point to the supplied UTF-8 string (in place version).

Parameters
strthe UTF-8 string to append in place
cthe code point
countthe number of times to append the code point

◆ append() [3/6]

static void append ( std::u32string &  str,
char32_t  c,
size_t  count 
)
inlinestatic

Appends count times the supplied code point to the supplied UTF-32 string (in place version).

Parameters
strthe UTF-32 string to append in place
cthe code point
countthe number of times to append the code point

◆ append() [4/6]

static std::string append ( const std::string_view &  str,
char  c,
size_t  count 
)
inlinestatic

Returns the supplied UTF-8 string with count times the supplied ascii character appended to it.

Parameters
strthe UTF-8 string to append onto
cthe ascii character
countthe number of times to append the ascii character
Returns
the appended UTF-8 string

◆ append() [5/6]

static std::string append ( const std::string &  str,
char32_t  c,
size_t  count 
)
inlinestatic

Returns the supplied UTF-8 string with count times the supplied code point appended to it.

Parameters
strthe UTF-8 string to append in place
cthe code point
countthe number of times to append the code point
Returns
the appended UTF-8 string

◆ append() [6/6]

static std::u32string append ( const std::u32string &  str,
char32_t  c,
size_t  count 
)
inlinestatic

Returns the supplied UTF-32 string with count times the supplied code point appended to it.

Parameters
strthe UTF-32 string to append in place
cthe code point
countthe number of times to append the code point
Returns
the appended UTF-32 string

◆ codePointCount() [1/2]

static size_t codePointCount ( const std::string_view &  str)
inlinestatic

Count the number of code points in the supplied UTF-8 string.

This is an O(n) operation.

◆ codePointCount() [2/2]

static size_t codePointCount ( const std::u32string_view &  str)
inlinestatic

Count the number of code points in the supplied UTF-32 string.

This is an O(1) operation.

◆ contains() [1/4]

static bool contains ( const StringT< CharT, T ... > &  str,
const SubstrT &  substring 
)
inlinestatic

Does the first string contain the second string?

◆ contains() [2/4]

static bool contains ( const CharT *  str,
const SubstrT &  substring 
)
inlinestatic

Does the first string contain the second string?

◆ contains() [3/4]

static bool contains ( const StringT< CharT, T ... > &  str,
const CharT &  c 
)
inlinestatic

Does the string contain the ascii char (UTF-8) / UTF-16 char (UTF-16) / code point (UTF-32)?

◆ contains() [4/4]

static bool contains ( const CharT *  str,
const CharT &  c 
)
inlinestatic

Does the string contain the ascii char (UTF-8) / UTF-16 char (UTF-16) / code point (UTF-32)?

◆ endsWith() [1/7]

static bool endsWith ( const StringT< CharT, T ... > &  str,
const SuffixT &  suffix 
)
inlinestatic

Does the string end with the specified suffix?

◆ endsWith() [2/7]

static bool endsWith ( const CharT *  str,
const SuffixT &  suffix 
)
inlinestatic

Does the string end with the specified suffix?

◆ endsWith() [3/7]

static bool endsWith ( const std::basic_string_view< CharT > &  str,
const std::basic_string_view< CharT > &  suffix 
)
inlinestatic

Does the first string end with the specified suffix?

◆ endsWith() [4/7]

static bool endsWith ( const char *  str,
const char  suffix 
)
inlinestatic

Does the UTF-8 string end with the specified ascii char?

◆ endsWith() [5/7]

static bool endsWith ( const std::string_view &  str,
const char  suffix 
)
inlinestatic

Does the UTF-8 string end with the specified ascii char?

◆ endsWith() [6/7]

static bool endsWith ( const char32_t *  str,
const char32_t  suffix 
)
inlinestatic

Does the UTF-32 string end with the specified ascii char?

◆ endsWith() [7/7]

static bool endsWith ( const std::u32string_view &  str,
const char32_t  suffix 
)
inlinestatic

Does the UTF-32 string end with the specified code point?

◆ equalsIgnoreCase() [1/2]

static bool equalsIgnoreCase ( const StringT< CharT, T ... > &  lhs,
const SubstrT &  rhs 
)
inlinestatic

Ignoring case, is the first string equal to the second string?

Todo:
Remove requirement for new string allocations.

◆ equalsIgnoreCase() [2/2]

static bool equalsIgnoreCase ( const CharT *  lhs,
const SubstrT &  rhs 
)
inlinestatic

Ignoring case, is the first string equal to the second string?

Todo:
Remove requirement for new string allocations.

◆ join() [1/4]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> join ( StringT< CharT, T ... >  delimiter,
const P1 &  p1,
const P &...  p 
)
inlinestatic

Call to-string on each of the objects and join the resulting strings together with the delimiter.

Parameters
delimiterthe string delimiter
p1the first object
psubsequent objects

◆ join() [2/4]

static std::basic_string<CharT> join ( StringT< CharT, T ... >  delimiter,
const P1 &  p1,
const P &...  p 
)
inlinestatic

Call to-string on each of the objects and join the resulting strings together with the delimiter.

Parameters
delimiterthe string delimiter
p1the first object
psubsequent objects

◆ join() [3/4]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> join ( const CharT *  delimiter,
const P1 &  p1,
const P &...  p 
)
inlinestatic

Call to-string on each of the objects and join the resulting strings together with the delimiter.

Parameters
delimiterthe string delimiter
p1the first object
psubsequent objects

◆ join() [4/4]

static std::basic_string<CharT> join ( const CharT *  delimiter,
const P1 &  p1,
const P &...  p 
)
inlinestatic

Call to-string on each of the objects and join the resulting strings together with the delimiter.

Parameters
delimiterthe string delimiter
p1the first object
psubsequent objects

◆ joinContainer() [1/6]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> joinContainer ( const CharT *  delimiter,
const C< T ... > &  container 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the delimiter.

Note that the delimiter in the parameter list of this function is reversed compared to the other join functions. This is done merely to ensure the correct template function is selected for containers.

Parameters
containerthe container of objects
delimiterthe UTF-8 string delimiter

◆ joinContainer() [2/6]

static std::basic_string<CharT> joinContainer ( const CharT *  delimiter,
const C< T ... > &  container 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the delimiter.

Note that the delimiter in the parameter list of this function is reversed compared to the other join functions. This is done merely to ensure the correct template function is selected for containers.

Parameters
containerthe container of objects
delimiterthe UTF-8 string delimiter

◆ joinContainer() [3/6]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> joinContainer ( const std::basic_string< CharT, std::char_traits< CharT >, AllocatorT > &  delimiter,
const C< T ... > &  container 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the delimiter.

Note that the delimiter in the parameter list of this function is reversed compared to the other join functions. This is done merely to ensure the correct template function is selected for containers.

Parameters
containerthe container of objects
delimiterthe UTF-8 string delimiter

◆ joinContainer() [4/6]

static std::basic_string<CharT> joinContainer ( const std::basic_string< CharT > &  delimiter,
const C< T ... > &  container 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the delimiter.

Note that the delimiter in the parameter list of this function is reversed compared to the other join functions. This is done merely to ensure the correct template function is selected for containers.

Parameters
containerthe container of objects
delimiterthe UTF-8 string delimiter

◆ joinContainer() [5/6]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> joinContainer ( std::basic_string_view< CharT >  delimiter,
const C< T ... > &  container 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the delimiter.

Parameters
containerthe container of objects
delimiterthe UTF-8 string view delimiter

◆ joinContainer() [6/6]

static std::basic_string<CharT> joinContainer ( std::basic_string_view< CharT >  delimiter,
const C< T ... > &  container 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the delimiter.

Parameters
containerthe container of objects
delimiterthe UTF-8 string view delimiter

◆ lastIndexOf() [1/2]

static size_t lastIndexOf ( const StringT< CharT, T ... > &  str,
const SubstrT &  substring 
)
inlinestatic

Get the character (UTF-8) / code point (UTF-32) position of the last index of the specified sub-string.

If the sub-string is not found npos is returned.

◆ lastIndexOf() [2/2]

static size_t lastIndexOf ( const CharT *  str,
const SubstrT &  substring 
)
inlinestatic

Get the character (UTF-8) / code point (UTF-32) position of the last index of the specified sub-string.

If the sub-string is not found npos is returned.

◆ lineLengths() [1/3]

static std::vector<size_t> lineLengths ( const StringT< char, T ... > &  text,
const std::regex &  lineBreakRegex,
bool  includeExtraTextAsLine = true 
)
inlinestatic

Determine the lengths of the lines in bytes, given the line break regular expression.

If the text ends with some non-line end characters, these characters form the last line and are counted in the line length results if the includeExtraTextAsLine boolean is true (the default).

Todo:
u32 regex?

◆ lineLengths() [2/3]

static std::vector<size_t> lineLengths ( const StringT< char, T ... > &  text,
bool  includeExtraTextAsLine = true 
)
inlinestatic

Given the supplied multi-line text string, determine the length of each line in bytes.

If the text ends with some non-line end characters, these characters form the last line and are counted in the line length results if the includeExtraTextAsLine boolean is true (the default).

This function matches the following line endings: CRLN, LNCR, LN, CR. If a different end of line marker regular expression is required, use the alternative overload and supply the regular expression.

Todo:
u32 regex?

◆ lineLengths() [3/3]

static std::vector<size_t> lineLengths ( const char *  text,
bool  includeExtraTextAsLine = true 
)
inlinestatic

Given the supplied multi-line text string, determine the length of each line in bytes.

If the text ends with some non-line end characters, these characters form the last line and are counted in the line length results if the includeExtraTextAsLine boolean is true (the default).

This function matches the following line endings: CRLN, LNCR, LN, CR. If a different end of line marker regular expression is required, use the alternative overload and supply the regular expression.

Todo:
u32 regex?

◆ matches()

static bool matches ( const std::string &  str,
const std::regex &  re 
)
inlinestatic

Does the string match the specified regular expression?

◆ occurrences() [1/5]

static size_t occurrences ( const CharT *  str,
const SubstrT &  substring 
)
inlinestatic

How many non-overlapping occurrences of the second string are found in the first string?

◆ occurrences() [2/5]

static size_t occurrences ( const StringT< CharT, T ... > &  str,
const SubstrT &  substring 
)
inlinestatic

How many non-overlapping occurrences of the second string are found in the first string?

◆ occurrences() [3/5]

static size_t occurrences ( const std::string &  str,
const std::regex &  regex 
)
inlinestatic

Count the number of non-overlapping occurrences of the supplied regular expression.

Todo:
u32 regex?

◆ occurrences() [4/5]

static size_t occurrences ( const char *  str,
const std::regex &  regex 
)
inlinestatic

Count the number of non-overlapping occurrences of the supplied regular expression.

Todo:
u32 regex?

◆ occurrences() [5/5]

static size_t occurrences ( const std::string_view &  str,
const std::regex &  regex 
)
inlinestatic

Count the number of non-overlapping occurrences of the supplied regular expression.

Todo:
u32 regex?

◆ padLeft() [1/3]

static std::string padLeft ( const std::string_view &  str,
unsigned int  width,
char  c = ' ' 
)
inlinestatic

Left pad the supplied UTF-8 string up to the specified width in code points.

The supplied ascii character is used for padding. The default character is a space.

◆ padLeft() [2/3]

static std::string padLeft ( const std::string_view &  str,
unsigned int  width,
char32_t  c 
)
inlinestatic

Left pad the supplied UTF-8 string up to the specified width in code points.

The supplied code point is used for padding.

◆ padLeft() [3/3]

static std::u32string padLeft ( const std::u32string_view &  str,
unsigned int  width,
char32_t  c = U' ' 
)
inlinestatic

Left pad the supplied UTF-32 string up to the specified width in code points.

The supplied code point is used for padding. The default character is a space.

◆ padRight() [1/3]

static std::string padRight ( const std::string_view &  str,
unsigned int  width,
char  c = ' ' 
)
inlinestatic

Right pad the supplied UTF-8 string up to the specified width in code points.

The supplied ascii character is used for padding. The default character is a space.

◆ padRight() [2/3]

static std::string padRight ( const std::string_view &  str,
unsigned int  width,
char32_t  c 
)
inlinestatic

Right pad the supplied UTF-8 string up to the specified width in code points.

The supplied code point is used for padding.

◆ padRight() [3/3]

static std::u32string padRight ( const std::u32string_view &  str,
unsigned int  width,
char32_t  c = U' ' 
)
inlinestatic

Right pad the supplied UTF-32 string up to the specified width in code points.

The supplied code point is used for padding. The default character is a space.

◆ prefixSuffixJoin() [1/4]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> prefixSuffixJoin ( const C< T ... > &  container,
const PrefixT< CharT, U ... > &  prefix,
const SuffixT< CharT, V ... > &  suffix 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the prefix and suffix.

Print the prefix before each string and the suffix after each string.

Parameters
containerthe container of objects
prefixthe string prefix
suffixthe string suffix

◆ prefixSuffixJoin() [2/4]

static std::string prefixSuffixJoin ( const C< T ... > &  container,
const PrefixT< CharT, U ... > &  prefix,
const SuffixT< CharT, V ... > &  suffix 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the prefix and suffix.

Print the prefix before each string and the suffix after each string.

Parameters
containerthe container of objects
prefixthe string prefix
suffixthe string suffix

◆ prefixSuffixJoin() [3/4]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> prefixSuffixJoin ( const C< T ... > &  container,
const CharT *  prefix,
const CharT *  suffix 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the prefix and suffix.

Print the prefix before each string and the suffix after each string.

Parameters
containerthe container of objects
prefixthe string prefix
suffixthe string suffix

◆ prefixSuffixJoin() [4/4]

static std::basic_string<CharT> prefixSuffixJoin ( const C< T ... > &  container,
const CharT *  prefix,
const CharT *  suffix 
)
inlinestatic

Call to-string on each of the objects in the container and join the resulting strings together with the prefix and suffix.

Print the prefix before each string and the suffix after each string.

Parameters
containerthe container of objects
prefixthe string prefix
suffixthe string suffix

◆ replaceAll() [1/9]

static std::basic_string<CharT> replaceAll ( const StringT< CharT, T ... > &  input,
const MatchT &  match,
const ReplacementT &  replacement 
)
inlinestatic

Replace all occurrences of the specified string with the supplied replacement.

◆ replaceAll() [2/9]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> replaceAll ( const StringT< CharT, T ... > &  input,
const MatchT &  match,
const ReplacementT &  replacement 
)
inlinestatic

Replace all occurrences of the specified string with the supplied replacement (specified allocator version).

◆ replaceAll() [3/9]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> replaceAll ( const CharT *  input,
const MatchT &  match,
const ReplacementT &  replacement 
)
inlinestatic

Replace all occurrences of the specified string with the supplied replacement.

◆ replaceAll() [4/9]

static std::basic_string<CharT, std::char_traits<CharT>, AllocatorT> replaceAll ( std::basic_string_view< CharT >  input,
std::basic_string_view< CharT >  match,
std::basic_string_view< CharT >  replacement,
size_t *  count = nullptr 
)
inlinestatic

Replace all occurrences of the specified string with the supplied replacement.

◆ replaceAll() [5/9]

static std::basic_string<CharT> replaceAll ( std::basic_string_view< CharT >  input,
std::basic_string_view< CharT >  match,
std::basic_string_view< CharT >  replacement,
size_t *  count = nullptr 
)
inlinestatic

Replace all occurrences of the specified string with the supplied replacement.

◆ replaceAll() [6/9]

static std::string replaceAll ( std::string_view  input,
std::string_view  match,
std::string_view  replacement,
size_t *  count = nullptr 
)
inlinestatic

Replace all occurrences of the specified string with the supplied replacement.

◆ replaceAll() [7/9]

static std::u32string replaceAll ( std::u32string_view  input,
std::u32string_view  match,
std::u32string_view  replacement,
size_t *  count = nullptr 
)
inlinestatic

Replace all occurrences of the specified string with the supplied replacement.

◆ replaceAll() [8/9]

static std::string replaceAll ( const char *  input,
const std::regex &  regex,
const ReplacementT &  replacement 
)
inlinestatic

Replace all occurrences of the regular expression in the input string with the replacement string.

Todo:
UTF-32 version?

◆ replaceAll() [9/9]

static std::string replaceAll ( const StringT< CharT, T ... > &  input,
const std::regex &  regex,
const ReplacementT &  replacement 
)
inlinestatic

Replace all occurrences of the regular expression in the input string with the replacement string.

Todo:
UTF-32 version?

◆ simplify()

static std::string simplify ( const std::string_view &  input)
inlinestatic

Simplify whitespace (conflate blanks) from the supplied UTF-8 string.

Multiple blanks (tab/space) are conflated to single blanks and whitespace from the start and end of the string is removed.

As this is a destructive process, a new string is returned.

◆ split() [1/3]

static std::vector<std::string_view> split ( const std::string_view &  input,
const std::regex &  delimiter,
bool  returnDelimiters = false,
bool  compress = true 
)
inlinestatic

Split the input string on each of the occurrences of the specified delimiter regular expression.

The input string must remain valid after the call, or the resulting string views will be invalid.

Parameters
inputthe input string to split
delimiterthe regular expression delimiter marking each split
returnDelimiterswhen true, the delimiter matches are also returned
compressfalse returns empty strings where multiple delimiters touch

◆ split() [2/3]

static std::vector<std::string_view> split ( const std::string_view &  input,
const std::string_view &  delimiter,
bool  compress = true 
)
inlinestatic

Split the input string on each of the occurrences of the specified delimiter.

Parameters
inputthe input string to split
delimiterthe string delimiter marking each split
compressfalse returns empty strings where multiple delimiters touch

◆ split() [3/3]

static std::vector<std::u32string_view> split ( const std::u32string_view &  input,
const std::u32string_view &  delimiter,
bool  compress = true 
)
inlinestatic

Split the input string on each of the occurrences of the specified delimiter.

Parameters
inputthe input string to split
delimiterthe string delimiter marking each split
compressfalse returns empty strings where multiple delimiters touch

◆ splitAndTrim() [1/3]

static std::vector<std::string_view> splitAndTrim ( const std::string_view &  input,
const std::regex &  delimiter,
bool  returnDelimiters = false,
bool  compress = true 
)
inlinestatic

Split the input string on each of the occurrences of the specified delimiter regular expression and subsequently trim the resulting strings.

The input string must remain valid after the call, or the resulting string views will be invalid.

Parameters
inputthe input string to split
delimiterthe regular expression delimiter marking each split
returnDelimiterswhen true, the delimiter matches are also returned
compressfalse returns empty strings where multiple delimiters touch

◆ splitAndTrim() [2/3]

static std::vector<std::string_view> splitAndTrim ( const std::string_view &  input,
const std::string_view &  delimiter,
bool  compress = true 
)
inlinestatic

Split the input string on each of the occurrences of the specified delimiter and subsequently trim the resulting strings.

Parameters
inputthe input string to split
delimiterthe string delimiter marking each split
compressfalse returns empty strings where multiple delimiters touch

◆ splitAndTrim() [3/3]

static std::vector<std::u32string_view> splitAndTrim ( const std::u32string_view &  input,
const std::u32string_view &  delimiter,
bool  compress = true 
)
inlinestatic

Split the input string on each of the occurrences of the specified delimiter and subsequently trim the resulting strings.

Parameters
inputthe input string to split
delimiterthe string delimiter marking each split
compressfalse returns empty strings where multiple delimiters touch

◆ startsWith() [1/6]

static bool startsWith ( const StringT< CharT, T ... > &  str,
const PrefixT &  prefix 
)
inlinestatic

Does the string start with the specified prefix?

◆ startsWith() [2/6]

static bool startsWith ( const StringT< CharT, T ... > &  str,
CharT  prefix 
)
inlinestatic

Does the string start with the specified prefix?

◆ startsWith() [3/6]

static bool startsWith ( const CharT *  str,
const PrefixT &  prefix 
)
inlinestatic

Does the string start with the specified prefix?

◆ startsWith() [4/6]

static bool startsWith ( const CharT *  str,
CharT  prefix 
)
inlinestatic

Does the string start with the specified prefix?

◆ startsWith() [5/6]

static bool startsWith ( const std::basic_string_view< CharT > &  str,
const std::basic_string_view< CharT > &  prefix 
)
inlinestatic

Does the string start with the specified prefix?

◆ startsWith() [6/6]

static bool startsWith ( const std::basic_string_view< CharT > &  str,
CharT  prefix 
)
inlinestatic

Does the string start with the specified prefix?

◆ startsWithRegex()

static bool startsWithRegex ( const std::string &  str,
const std::regex &  prefix 
)
inlinestatic

Does the string start with the specified regular expression?

◆ toLower() [1/2]

static std::string toLower ( const std::string_view &  s)
inlinestatic

Convert the supplied UTF-8 string to lowercase.

◆ toLower() [2/2]

static std::u32string toLower ( const std::u32string_view &  s)
inlinestatic

Convert the supplied UTF-32 string to lowercase.

◆ toStringContainer()

static ContainerT<std::basic_string<CharT> > toStringContainer ( const ContainerT< std::basic_string_view< CharT >, T ... > &  input)
inlinestatic

Convert the container of string views to a container of strings.

◆ toUpper() [1/2]

static std::string toUpper ( const std::string_view &  s)
inlinestatic

Convert the supplied UTF-8 string to uppercase.

◆ toUpper() [2/2]

static std::u32string toUpper ( const std::u32string_view &  s)
inlinestatic

Convert the supplied UTF-32 string to uppercase.

◆ trim() [1/2]

static std::string_view trim ( const std::string_view &  input)
inlinestatic

Trim whitespace from the beginning and end of the supplied UTF-8 string.

◆ trim() [2/2]

static std::u32string_view trim ( const std::u32string_view &  input)
inlinestatic

Trim whitespace from the beginning and end of the supplied UTF-32 string.

◆ trimLeft() [1/2]

static std::string_view trimLeft ( const std::string_view &  input)
inlinestatic

Trim whitespace from the beginning of the supplied UTF-8 string.

◆ trimLeft() [2/2]

static std::u32string_view trimLeft ( const std::u32string_view &  input)
inlinestatic

Trim whitespace from the beginning of the supplied UTF-32 string.

◆ trimRight() [1/2]

static std::string_view trimRight ( const std::string_view &  input)
inlinestatic

Trim whitespace from the end of the supplied UTF-8 string.

◆ trimRight() [2/2]

static std::u32string_view trimRight ( const std::u32string_view &  input)
inlinestatic

Trim whitespace from the end of the supplied UTF-32 string.


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