From e6472db0b500c8374a7ba3aeded60ec4731fe7e6 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 6 Mar 2020 13:47:22 +0100 Subject: [PATCH] Add C string variants of starts_with() and ends_with(). --- include/lol/base/private/string.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/lol/base/private/string.h b/include/lol/base/private/string.h index f21f8f1f..7c5e7042 100644 --- a/include/lol/base/private/string.h +++ b/include/lol/base/private/string.h @@ -74,7 +74,7 @@ std::vector> split(std::basic_string const &s, return split(s, std::basic_string(seps)); } -// Check whether a string starts or ends with a given substring +// Check whether a string starts with a given substring template bool starts_with(std::basic_string const &s, std::basic_string const &prefix) @@ -89,6 +89,13 @@ bool starts_with(std::basic_string const &s, T const *prefix) return starts_with(s, std::basic_string(prefix)); } +template +bool starts_with(T const *s, T const *suffix) +{ + return starts_with(std::basic_string(s), std::basic_string(suffix)); +} + +// Check whether a string ends with a given substring template bool ends_with(std::basic_string const &s, std::basic_string const &suffix) @@ -103,6 +110,12 @@ bool ends_with(std::basic_string const &s, T const *suffix) return ends_with(s, std::basic_string(suffix)); } +template +bool ends_with(T const *s, T const *suffix) +{ + return ends_with(std::basic_string(s), std::basic_string(suffix)); +} + // Convert a string to lowercase or uppercase template std::basic_string tolower(std::basic_string const &s)