From 2319fd930710cc7a81864cf5953c6b35c56eb975 Mon Sep 17 00:00:00 2001 From: gwdwyy Date: Sat, 31 Aug 2013 16:14:25 +0800 Subject: [PATCH] update cppcommon for endswith in str_funst.h --- src/cppcommon/str_functs.cpp | 25 +++++++++++-------------- src/cppcommon/str_functs.h | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/cppcommon/str_functs.cpp b/src/cppcommon/str_functs.cpp index 8d41ce9..a0075ad 100644 --- a/src/cppcommon/str_functs.cpp +++ b/src/cppcommon/str_functs.cpp @@ -228,11 +228,6 @@ namespace CPPCOMMON return res; } - bool strStartsWith(const string& str, const string& prefix) - { - return str.substr(0, prefix.size()) == prefix; - } - } #ifdef TEST_STR_FUNCTS @@ -302,15 +297,17 @@ int main() // s = utf8ToGbk(s); // cout< str.length()) + { + return false; + } + return 0 == str.compare(0, prefix.length(), prefix); + } + + inline bool strEndsWith(const string& str, const string& suffix) + { + if(suffix.length() > str.length()) + { + return false; + } + return 0 == str.compare(str.length() - suffix.length(), suffix.length(), suffix); + } } #endif