From d92c8909d4dbfc3919c7353b74d2ff3a5ddfcee2 Mon Sep 17 00:00:00 2001 From: Oleg Morozenkov Date: Tue, 4 Aug 2015 09:17:19 +0300 Subject: Fix StringTools --- src/tools/StringTools.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/tools') 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()); -- cgit v1.2.3