diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-08-04 09:17:19 +0300 |
---|---|---|
committer | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-08-04 09:17:19 +0300 |
commit | d92c8909d4dbfc3919c7353b74d2ff3a5ddfcee2 (patch) | |
tree | 13f79edf9b7483648befb881add16ca623171ea5 | |
parent | 99072def67e54d664edd96b9c0f124c4f09cedee (diff) |
Fix StringTools
-rw-r--r-- | include/tgbot/tools/StringTools.h | 4 | ||||
-rw-r--r-- | src/tools/StringTools.cpp | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/include/tgbot/tools/StringTools.h b/include/tgbot/tools/StringTools.h index a8b4af1..6c01575 100644 --- a/include/tgbot/tools/StringTools.h +++ b/include/tgbot/tools/StringTools.h @@ -33,14 +33,14 @@ namespace StringTools { /** - * Checks if first string is starting with second string and vice-versa + * Checks if first string is starting with second string * @param str1 First string * @param str2 Second string */ bool startsWith(const std::string& str1, const std::string& str2); /** - * Checks if first string is ending with second string and vice-versa + * Checks if first string is ending with second string * @param str1 First string * @param str2 Second string */ diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp index 188e71c..deb8fa1 100644 --- a/src/tools/StringTools.cpp +++ b/src/tools/StringTools.cpp @@ -31,7 +31,10 @@ using namespace std; namespace StringTools { bool startsWith(const string& str1, const string& str2) { - string::const_iterator it1(str1.begin()); + if (str1.length() < str2.length()) { + return false; + } + string::const_iterator it1(str1.begin()); string::const_iterator end1(str1.end()); string::const_iterator it2(str2.begin()); string::const_iterator end2(str2.end()); @@ -46,7 +49,10 @@ bool startsWith(const string& str1, const string& str2) { } bool endsWith(const string& str1, const string& str2) { - string::const_iterator it1(str1.end()); + if (str1.length() < str2.length()) { + return false; + } + string::const_iterator it1(str1.end()); string::const_iterator begin1(str1.begin()); string::const_iterator it2(str2.end()); string::const_iterator begin2(str2.begin()); |