WPILibC++ 2023.4.3-108-ge5452e3
StringExtras.h File Reference
#include <limits>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>

Go to the source code of this file.

Namespaces

namespace  wpi
 
namespace  wpi::detail
 detail namespace with internal helper functions
 

Functions

constexpr char wpi::hexdigit (unsigned X, bool LowerCase=false) noexcept
 hexdigit - Return the hexadecimal character for the given number X (which should be less than 16). More...
 
constexpr unsigned wpi::hexDigitValue (char C) noexcept
 Interpret the given character C as a hexadecimal digit and return its value. More...
 
constexpr bool wpi::isDigit (char C) noexcept
 Checks if character C is one of the 10 decimal digits. More...
 
constexpr bool wpi::isHexDigit (char C) noexcept
 Checks if character C is a hexadecimal numeric character. More...
 
constexpr bool wpi::isAlpha (char C) noexcept
 Checks if character C is a valid letter as classified by "C" locale. More...
 
constexpr bool wpi::isAlnum (char C) noexcept
 Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classified by "C" locale. More...
 
constexpr bool wpi::isASCII (char C) noexcept
 Checks whether character C is valid ASCII (high bit is zero). More...
 
constexpr bool wpi::isPrint (char C) noexcept
 Checks whether character C is printable. More...
 
constexpr char wpi::toLower (char x) noexcept
 Returns the corresponding lowercase character if x is uppercase. More...
 
constexpr char wpi::toUpper (char x) noexcept
 Returns the corresponding uppercase character if x is lowercase. More...
 
std::string wpi::utohexstr (unsigned long long val, bool lowerCase=false)
 
constexpr bool wpi::equals (std::string_view lhs, std::string_view rhs) noexcept
 equals - Check for string equality, this is more efficient than compare() when the relative ordering of inequal strings isn't needed. More...
 
int wpi::compare_lower (std::string_view lhs, std::string_view rhs) noexcept
 compare_lower - Compare two strings, ignoring case. More...
 
constexpr bool wpi::equals_lower (std::string_view lhs, std::string_view rhs) noexcept
 equals_lower - Check for string equality, ignoring case. More...
 
std::string_view::size_type wpi::find_lower (std::string_view str, char ch, std::string_view::size_type from=0) noexcept
 Search for the first character ch in str, ignoring case. More...
 
std::string_view::size_type wpi::find_lower (std::string_view str, std::string_view other, std::string_view::size_type from=0) noexcept
 Search for the first string other in str, ignoring case. More...
 
std::string_view::size_type wpi::find_lower (std::string_view str, const char *other, std::string_view::size_type from=0) noexcept
 Search for the first string other in str, ignoring case. More...
 
std::string_view::size_type wpi::rfind_lower (std::string_view str, char ch, std::string_view::size_type from=std::string_view::npos) noexcept
 Search for the last character ch in str, ignoring case. More...
 
std::string_view::size_type wpi::rfind_lower (std::string_view str, std::string_view other) noexcept
 Search for the last string other in str, ignoring case. More...
 
std::string_view::size_type wpi::rfind_lower (std::string_view str, const char *other) noexcept
 Search for the last string other in str, ignoring case. More...
 
constexpr std::string_view wpi::substr (std::string_view str, std::string_view::size_type start, std::string_view::size_type n=std::string_view::npos) noexcept
 Returns the substring of str from [start, start + n). More...
 
constexpr bool wpi::starts_with (std::string_view str, std::string_view prefix) noexcept
 Checks if str starts with the given prefix. More...
 
constexpr bool wpi::starts_with (std::string_view str, char prefix) noexcept
 Checks if str starts with the given prefix. More...
 
constexpr bool wpi::starts_with (std::string_view str, const char *prefix) noexcept
 Checks if str starts with the given prefix. More...
 
bool wpi::starts_with_lower (std::string_view str, std::string_view prefix) noexcept
 Checks if str starts with the given prefix, ignoring case. More...
 
constexpr bool wpi::starts_with_lower (std::string_view str, char prefix) noexcept
 Checks if str starts with the given prefix, ignoring case. More...
 
bool wpi::starts_with_lower (std::string_view str, const char *prefix) noexcept
 Checks if str starts with the given prefix, ignoring case. More...
 
constexpr bool wpi::ends_with (std::string_view str, std::string_view suffix) noexcept
 Checks if str ends with the given suffix. More...
 
constexpr bool wpi::ends_with (std::string_view str, char suffix) noexcept
 Checks if str ends with the given suffix. More...
 
constexpr bool wpi::ends_with (std::string_view str, const char *suffix) noexcept
 Checks if str ends with the given suffix. More...
 
bool wpi::ends_with_lower (std::string_view str, std::string_view suffix) noexcept
 Checks if str ends with the given suffix, ignoring case. More...
 
constexpr bool wpi::ends_with_lower (std::string_view str, char suffix) noexcept
 Checks if str ends with the given suffix, ignoring case. More...
 
bool wpi::ends_with_lower (std::string_view str, const char *suffix) noexcept
 Checks if str ends with the given suffix, ignoring case. More...
 
constexpr bool wpi::contains (std::string_view str, std::string_view other) noexcept
 Checks if str contains the substring other. More...
 
constexpr bool wpi::contains (std::string_view str, char ch) noexcept
 Checks if str contains the substring other. More...
 
constexpr bool wpi::contains (std::string_view str, const char *other) noexcept
 Checks if str contains the substring other. More...
 
bool wpi::contains_lower (std::string_view str, std::string_view other) noexcept
 Checks if str contains the substring other, ignoring case. More...
 
bool wpi::contains_lower (std::string_view str, char ch) noexcept
 Checks if str contains the substring other, ignoring case. More...
 
bool wpi::contains_lower (std::string_view str, const char *other) noexcept
 Checks if str contains the substring other, ignoring case. More...
 
constexpr std::string_view wpi::drop_front (std::string_view str, std::string_view::size_type n=1) noexcept
 Return a string_view equal to str but with the first n elements dropped. More...
 
constexpr std::string_view wpi::drop_back (std::string_view str, std::string_view::size_type n=1) noexcept
 Return a string_view equal to str but with the last n elements dropped. More...
 
constexpr std::string_view wpi::take_front (std::string_view str, std::string_view::size_type n=1) noexcept
 Returns a view equal to str but with only the first n elements remaining. More...
 
constexpr std::string_view wpi::take_back (std::string_view str, std::string_view::size_type n=1) noexcept
 Returns a view equal to str but with only the last n elements remaining. More...
 
constexpr std::string_view wpi::slice (std::string_view str, std::string_view::size_type start, std::string_view::size_type end) noexcept
 Returns a reference to the substring of str from [start, end). More...
 
constexpr std::pair< std::string_view, std::string_viewwpi::split (std::string_view str, char separator) noexcept
 Splits str into two substrings around the first occurrence of a separator character. More...
 
constexpr std::pair< std::string_view, std::string_viewwpi::split (std::string_view str, std::string_view separator) noexcept
 Splits str into two substrings around the first occurrence of a separator string. More...
 
constexpr std::pair< std::string_view, std::string_viewwpi::rsplit (std::string_view str, char separator) noexcept
 Splits str into two substrings around the last occurrence of a separator character. More...
 
constexpr std::pair< std::string_view, std::string_viewwpi::rsplit (std::string_view str, std::string_view separator) noexcept
 Splits str into two substrings around the last occurrence of a separator string. More...
 
void wpi::split (std::string_view str, SmallVectorImpl< std::string_view > &arr, std::string_view separator, int maxSplit=-1, bool keepEmpty=true) noexcept
 Splits str into substrings around the occurrences of a separator string. More...
 
void wpi::split (std::string_view str, SmallVectorImpl< std::string_view > &arr, char separator, int maxSplit=-1, bool keepEmpty=true) noexcept
 Splits str into substrings around the occurrences of a separator character. More...
 
constexpr std::string_view wpi::ltrim (std::string_view str, char ch) noexcept
 Returns str with consecutive ch characters starting from the the left removed. More...
 
constexpr std::string_view wpi::ltrim (std::string_view str, std::string_view chars=" \t\n\v\f\r") noexcept
 Returns str with consecutive characters in chars starting from the left removed. More...
 
constexpr std::string_view wpi::rtrim (std::string_view str, char ch) noexcept
 Returns str with consecutive Char characters starting from the right removed. More...
 
constexpr std::string_view wpi::rtrim (std::string_view str, std::string_view chars=" \t\n\v\f\r") noexcept
 Returns str with consecutive characters in chars starting from the right removed. More...
 
constexpr std::string_view wpi::trim (std::string_view str, char ch) noexcept
 Returns str with consecutive ch characters starting from the left and right removed. More...
 
constexpr std::string_view wpi::trim (std::string_view str, std::string_view chars=" \t\n\v\f\r") noexcept
 Returns str with consecutive characters in chars starting from the left and right removed. More...
 
bool wpi::detail::GetAsUnsignedInteger (std::string_view str, unsigned radix, unsigned long long &result) noexcept
 
bool wpi::detail::GetAsSignedInteger (std::string_view str, unsigned radix, long long &result) noexcept
 
bool wpi::detail::ConsumeUnsignedInteger (std::string_view &str, unsigned radix, unsigned long long &result) noexcept
 
bool wpi::detail::ConsumeSignedInteger (std::string_view &str, unsigned radix, long long &result) noexcept
 
template<typename T , std::enable_if_t< std::numeric_limits< T >::is_signed, bool > = true>
std::optional< T > wpi::parse_integer (std::string_view str, unsigned radix) noexcept
 Parses the string str as an integer of the specified radix. More...
 
template<typename T , std::enable_if_t< std::numeric_limits< T >::is_signed, bool > = true>
std::optional< T > wpi::consume_integer (std::string_view *str, unsigned radix) noexcept
 Parses the string str as an integer of the specified radix. More...
 
template<typename T >
std::optional< T > wpi::parse_float (std::string_view str) noexcept
 Parses the string str as a floating point value. More...
 
template<>
std::optional< float > wpi::parse_float< float > (std::string_view str) noexcept
 
template<>
std::optional< double > wpi::parse_float< double > (std::string_view str) noexcept
 
template<>
std::optional< long double > wpi::parse_float< long double > (std::string_view str) noexcept
 
std::pair< std::string_view, std::string_viewwpi::UnescapeCString (std::string_view str, SmallVectorImpl< char > &buf)
 Unescapes a C-style string (reverse operation to raw_ostream::write_escaped). More...