From 50faff29a99e31cb88dffdb43178a4e29e71351a Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 3 Jul 2015 02:53:27 +0200 Subject: [PATCH] add a startsWith util function Boost has a starts_with in the string algorithms lib, but we do not want to pull that in everywhere. --- src/lib/util.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib/util.hpp b/src/lib/util.hpp index 6c36c2959..961439894 100644 --- a/src/lib/util.hpp +++ b/src/lib/util.hpp @@ -142,6 +142,20 @@ namespace util { + /** check if string starts with a given prefix */ + inline bool + startsWith (string const& str, string const& prefix) + { + return 0 == str.rfind(prefix, 0); + } + + inline bool + startsWith (string const& str, const char* prefix) + { + return 0 == str.rfind(prefix, 0); + } + + /** shortcut for containment test on a map */ template inline bool