From 4a4225fd72cd26cf8ac8767ad76239a18900c68b Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 23 Mar 2017 18:38:25 +0300 Subject: [PATCH] Fix char index search --- runtime/src/main/cpp/KString.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/src/main/cpp/KString.cpp b/runtime/src/main/cpp/KString.cpp index 6b12c20b43c..acf910c8d1b 100644 --- a/runtime/src/main/cpp/KString.cpp +++ b/runtime/src/main/cpp/KString.cpp @@ -371,7 +371,7 @@ KInt Kotlin_Char_digitOf(KChar ch, KInt radix) { KInt Kotlin_String_indexOfChar(KString thiz, KChar ch, KInt fromIndex) { if (fromIndex < 0 || fromIndex > thiz->count_) { - return false; + return -1; } KInt count = thiz->count_; const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, fromIndex); @@ -384,12 +384,12 @@ KInt Kotlin_String_indexOfChar(KString thiz, KChar ch, KInt fromIndex) { KInt Kotlin_String_lastIndexOfChar(KString thiz, KChar ch, KInt fromIndex) { if (fromIndex < 0 || fromIndex > thiz->count_ || thiz->count_ == 0) { - return false; + return -1; } KInt count = thiz->count_; - KInt index = count - 1; + KInt index = fromIndex; const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, index); - while (index >= fromIndex) { + while (index >= 0) { if (*thizRaw-- == ch) return index; index--; } @@ -416,7 +416,7 @@ KInt Kotlin_String_indexOfString(KString thiz, KString other, KInt fromIndex) { KInt Kotlin_String_lastIndexOfString(KString thiz, KString other, KInt fromIndex) { if (fromIndex < 0 || fromIndex > thiz->count_ || thiz->count_ == 0 || other->count_ > thiz->count_ - fromIndex) { - return false; + return -1; } KInt count = thiz->count_; KInt otherCount = other->count_;