summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVinzenz Feenstra <evilissimo@gmail.com>2014-02-26 15:47:22 +0100
committerVinzenz Feenstra <evilissimo@gmail.com>2014-02-26 15:47:22 +0100
commitbfa38b51663d59cfaec7aa469565c09a4ec05275 (patch)
treeefde894b3fa634fbde262a942b900f2ce0b3c2cb
parenta9aae3000f2529dc773a876f3a3908eb9dcb824c (diff)
Fix string version of begins_with
Signed-off-by: Vinzenz Feenstra <evilissimo@gmail.com>
-rw-r--r--core/ustring.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index b0f06c6ab6..2384ce5bd6 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -2491,19 +2491,21 @@ bool String::begins_with(const String& p_string) const {
const CharType *src=&p_string[0];
const CharType *str=&operator[](0);
- for (int i=0;i<l;i++) {
+ int i = 0;
+ for (;i<l;i++) {
if (src[i]!=str[i])
return false;
}
- return true;
+ // only if i == l the p_string matches the beginning
+ return i == l;
}
bool String::begins_with(const char* p_string) const {
int l=length();
- if (l==0)
+ if (l==0||!p_string)
return false;
const CharType *str=&operator[](0);