From 2602f53585fded5b39cae6b8839f19589400f9b4 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Tue, 6 Apr 2021 13:16:00 +0200 Subject: [PATCH] Add tools: StrStartsWith, StrEndsWith --- fairmq/tools/Strings.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fairmq/tools/Strings.h b/fairmq/tools/Strings.h index 3080b02a..3e25b984 100644 --- a/fairmq/tools/Strings.h +++ b/fairmq/tools/Strings.h @@ -39,6 +39,24 @@ inline auto ToStrVector(const int argc, char*const* argv, const bool dropProgram } } +inline bool StrStartsWith(std::string const& str, std::string const& start) +{ + if (str.length() >= start.length()) { + return (0 == str.compare(0, start.length(), start)); + } else { + return false; + } +} + +inline bool StrEndsWith(std::string const& str, std::string const& end) +{ + if (str.length() >= end.length()) { + return (0 == str.compare(str.length() - end.length(), end.length(), end)); + } else { + return false; + } +} + } // namespace fair::mq::tools #endif /* FAIR_MQ_TOOLS_STRINGS_H */