Bläddra i källkod

Add C string variants of starts_with() and ends_with().

wip/core-clipp
Sam Hocevar 4 år sedan
förälder
incheckning
e6472db0b5
1 ändrade filer med 14 tillägg och 1 borttagningar
  1. +14
    -1
      include/lol/base/private/string.h

+ 14
- 1
include/lol/base/private/string.h Visa fil

@@ -74,7 +74,7 @@ std::vector<std::basic_string<T>> split(std::basic_string<T> const &s,
return split(s, std::basic_string<T>(seps));
}

// Check whether a string starts or ends with a given substring
// Check whether a string starts with a given substring
template<typename T>
bool starts_with(std::basic_string<T> const &s,
std::basic_string<T> const &prefix)
@@ -89,6 +89,13 @@ bool starts_with(std::basic_string<T> const &s, T const *prefix)
return starts_with(s, std::basic_string<T>(prefix));
}

template<typename T>
bool starts_with(T const *s, T const *suffix)
{
return starts_with(std::basic_string<T>(s), std::basic_string<T>(suffix));
}

// Check whether a string ends with a given substring
template<typename T>
bool ends_with(std::basic_string<T> const &s,
std::basic_string<T> const &suffix)
@@ -103,6 +110,12 @@ bool ends_with(std::basic_string<T> const &s, T const *suffix)
return ends_with(s, std::basic_string<T>(suffix));
}

template<typename T>
bool ends_with(T const *s, T const *suffix)
{
return ends_with(std::basic_string<T>(s), std::basic_string<T>(suffix));
}

// Convert a string to lowercase or uppercase
template<typename T>
std::basic_string<T> tolower(std::basic_string<T> const &s)


Laddar…
Avbryt
Spara