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