summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tgbot/tools/StringTools.h4
-rw-r--r--src/tools/StringTools.cpp10
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());