General Utility Library for C++14  2.11
Functions
gul14/substring_checks.h

Detailed Description

Checking whether a string contains, ends with, or starts with another string.

Functions

constexpr bool gul14::contains (string_view haystack, string_view needle) noexcept
 Determine whether a string contains another string. More...
 
constexpr bool gul14::contains (string_view haystack, char needle) noexcept
 Determine whether a string contains a certain character. More...
 
constexpr bool gul14::ends_with (string_view str, string_view suffix) noexcept
 Determine whether a string ends with another string. More...
 
constexpr bool gul14::ends_with (string_view str, char c) noexcept
 Determine whether a string ends with a certain character. More...
 
constexpr bool gul14::starts_with (string_view str, string_view prefix) noexcept
 Determine whether a string starts with another string. More...
 
constexpr bool gul14::starts_with (string_view str, char c) noexcept
 Determine whether a string starts with a certain character. More...
 
constexpr bool gul14::equals_nocase (string_view str1, string_view str2) noexcept
 Determine whether a string is equal to another one, making no distinction between upper and lower case ASCII characters. More...
 
constexpr bool gul14::contains_nocase (string_view haystack, string_view needle) noexcept
 Determine whether a string contains another string. More...
 
constexpr bool gul14::contains_nocase (string_view haystack, char needle) noexcept
 Determine whether a string contains a certain character. More...
 
constexpr bool gul14::ends_with_nocase (string_view str, string_view suffix) noexcept
 Determine whether a string ends with another string. More...
 
constexpr bool gul14::ends_with_nocase (string_view str, char c) noexcept
 Determine whether a string ends with a certain character. More...
 
constexpr bool gul14::starts_with_nocase (string_view str, string_view prefix) noexcept
 Determine whether a string starts with another string. More...
 
constexpr bool gul14::starts_with_nocase (string_view str, char c) noexcept
 Determine whether a string starts with a certain character. More...
 

Function Documentation

◆ contains() [1/2]

constexpr bool gul14::contains ( string_view  haystack,
char  needle 
)
inlineconstexprnoexcept

Determine whether a string contains a certain character.

The comparison is case sensitive.

Parameters
haystackThe string in which to search.
needleThe character that should be searched for.
Returns
true if haystack contains at least one occurrence of needle, false otherwise.
See also
contains(string_view, string_view), contains_nocase(string_view, char), ends_with(string_view, char), starts_with(string_view, char)

◆ contains() [2/2]

constexpr bool gul14::contains ( string_view  haystack,
string_view  needle 
)
inlineconstexprnoexcept

Determine whether a string contains another string.

The comparison is case sensitive. If the searched-for string is empty, the result is true.

Parameters
haystackThe string in which to search.
needleThe string that should be searched for.
Returns
true if haystack contains at least one occurrence of needle, false otherwise.
See also
contains(string_view, char), contains_nocase(string_view, string_view), ends_with(string_view, string_view), starts_with(string_view, string_view)

◆ contains_nocase() [1/2]

constexpr bool gul14::contains_nocase ( string_view  haystack,
char  needle 
)
inlineconstexprnoexcept

Determine whether a string contains a certain character.

The comparison is case insensitive as far as ASCII characters are concerned (C locale).

Parameters
haystackThe string in which to search.
needleThe character that should be searched for.
Returns
true if haystack contains at least one occurrence of needle, false otherwise.
Since
GUL version 1.7
See also
contains_nocase(string_view, string_view), contains(string_view, char), ends_with_nocase(string_view, char), starts_with_nocase(string_view, char)

References gul14::lowercase_ascii().

◆ contains_nocase() [2/2]

constexpr bool gul14::contains_nocase ( string_view  haystack,
string_view  needle 
)
inlineconstexprnoexcept

Determine whether a string contains another string.

The comparison is case insensitive as far as ASCII characters are concerned (C locale). If the searched-for string is empty, the result is true.

Parameters
haystackThe string in which to search.
needleThe string that should be searched for.
Returns
true if haystack contains at least one occurrence of needle, false otherwise.
Note
This function does not allocate memory to buffer the case-transformed input strings. It might therefore have lower performance than combining contains() and lowercase_ascii().
Since
GUL version 1.7
See also
contains_nocase(string_view, char), contains(string_view, string_view), ends_with_nocase(string_view, string_view), starts_with_nocase(string_view, string_view)

References gul14::lowercase_ascii().

◆ ends_with() [1/2]

constexpr bool gul14::ends_with ( string_view  str,
char  c 
)
inlineconstexprnoexcept

Determine whether a string ends with a certain character.

The comparison is case sensitive.

Parameters
strThe string to be tested.
cThe character to be looked for at the end of str.
Returns
true if str ends with c, false otherwise.
See also
ends_with(string_view, string_view), ends_with_nocase(string_view, char), starts_with(string_view, char), contains(string_view, char)

◆ ends_with() [2/2]

constexpr bool gul14::ends_with ( string_view  str,
string_view  suffix 
)
inlineconstexprnoexcept

Determine whether a string ends with another string.

The comparison is case sensitive. If the searched-for suffix is empty, the result is true.

Parameters
strThe full string to be tested.
suffixThe suffix to be looked for at the end of str.
Returns
true if str ends with suffix, false otherwise.
See also
ends_with(string_view, char), ends_with_nocase(string_view, string_view), starts_with(string_view, string_view), contains(string_view, string_view)

◆ ends_with_nocase() [1/2]

constexpr bool gul14::ends_with_nocase ( string_view  str,
char  c 
)
inlineconstexprnoexcept

Determine whether a string ends with a certain character.

The comparison is case insensitive as far as ASCII characters are concerned (C locale).

Parameters
strThe string to be tested.
cThe character to be looked for at the end of str.
Returns
true if str ends with c, false otherwise.
Since
GUL version 1.7
See also
ends_with_nocase(string_view, string_view), ends_with(string_view, char), starts_with_nocase(string_view, char), contains_nocase(string_view, char)

References gul14::lowercase_ascii().

◆ ends_with_nocase() [2/2]

constexpr bool gul14::ends_with_nocase ( string_view  str,
string_view  suffix 
)
inlineconstexprnoexcept

Determine whether a string ends with another string.

The comparison is case insensitive as far as ASCII characters are concerned (C locale). If the searched-for suffix is empty, the result is true.

Parameters
strThe full string to be tested.
suffixThe suffix to be looked for at the end of str.
Returns
true if str ends with suffix, false otherwise.
Since
GUL version 1.7
See also
ends_with_nocase(string_view, char), ends_with(string_view, string_view), starts_with_nocase(string_view, string_view), contains_nocase(string_view, string_view)

References gul14::lowercase_ascii().

◆ equals_nocase()

constexpr bool gul14::equals_nocase ( string_view  str1,
string_view  str2 
)
inlineconstexprnoexcept

Determine whether a string is equal to another one, making no distinction between upper and lower case ASCII characters.

In other terms, this function performs a case insensitive string comparison using the C locale.

Parameters
str1,str2The two strings that should be compared.
Returns
true if the ASCII-lowercase versions of str1 and str2 are equal, or false otherwise.
Since
GUL version 2.1
See also
contains_nocase(string_view, string_view), ends_with_nocase(string_view, string_view), starts_with_nocase(string_view, string_view)

References gul14::lowercase_ascii().

◆ starts_with() [1/2]

constexpr bool gul14::starts_with ( string_view  str,
char  c 
)
inlineconstexprnoexcept

Determine whether a string starts with a certain character.

The comparison is case sensitive.

Parameters
strThe string to be tested.
cThe character to be looked for at the beginning of str.
Returns
true if str starts with c, false otherwise.
See also
starts_with(string_view, string_view), starts_with_nocase(string_view, char), ends_with(string_view, char), contains(string_view, char)

◆ starts_with() [2/2]

constexpr bool gul14::starts_with ( string_view  str,
string_view  prefix 
)
inlineconstexprnoexcept

Determine whether a string starts with another string.

The comparison is case sensitive. If the searched-for prefix is empty, the result is true.

Parameters
strThe full string to be tested.
prefixThe prefix to be looked for at the beginning of str.
Returns
true if str starts with prefix, false otherwise.
See also
starts_with(string_view, char), starts_with_nocase(string_view, string_view), ends_with(string_view, string_view), contains(string_view, string_view)

◆ starts_with_nocase() [1/2]

constexpr bool gul14::starts_with_nocase ( string_view  str,
char  c 
)
inlineconstexprnoexcept

Determine whether a string starts with a certain character.

The comparison is case insensitive as far as ASCII characters are concerned (C locale).

Parameters
strThe string to be tested.
cThe character to be looked for at the beginning of str.
Returns
true if str starts with c, false otherwise.
Since
GUL version 1.7
See also
starts_with_nocase(string_view, string_view), starts_with(string_view, char), ends_with_nocase(string_view, char), contains_nocase(string_view, char)

References gul14::lowercase_ascii().

◆ starts_with_nocase() [2/2]

constexpr bool gul14::starts_with_nocase ( string_view  str,
string_view  prefix 
)
inlineconstexprnoexcept

Determine whether a string starts with another string.

The comparison is case insensitive as far as ASCII characters are concerned (C locale). If the searched-for prefix is empty, the result is true.

Parameters
strThe full string to be tested.
prefixThe prefix to be looked for at the beginning of str.
Returns
true if str starts with prefix, false otherwise.
Since
GUL version 1.7
See also
starts_with_nocase(string_view, char), starts_with(string_view, string_view), ends_with_nocase(string_view, string_view), contains_nocase(string_view, string_view)

References gul14::lowercase_ascii().