From a8dad223324f66c997c0b5c439c98cbc928d39b9 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Tue, 25 Apr 2017 14:35:21 +0700 Subject: [PATCH] stdlib: Always find an empty substring This patch fixes the following tests: external_stdlib_text_StringTest/replace.kt external_stdlib_text_StringTest/replaceDelimited.kt external_stdlib_text_StringTest/replaceFirst.kt --- runtime/src/main/cpp/KString.cpp | 4 ++++ runtime/src/main/kotlin/kotlin/text/Strings.kt | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/src/main/cpp/KString.cpp b/runtime/src/main/cpp/KString.cpp index 4322937693a..c58f7027c84 100644 --- a/runtime/src/main/cpp/KString.cpp +++ b/runtime/src/main/cpp/KString.cpp @@ -1060,6 +1060,10 @@ KInt Kotlin_String_indexOfString(KString thiz, KString other, KInt fromIndex) { other->count_ > thiz->count_ - fromIndex) { return -1; } + // An empty string can be always found. + if (other->count_ == 0) { + return fromIndex; + } KInt count = thiz->count_; const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, fromIndex); const KChar* otherRaw = CharArrayAddressOfElementAt(other, 0); diff --git a/runtime/src/main/kotlin/kotlin/text/Strings.kt b/runtime/src/main/kotlin/kotlin/text/Strings.kt index 282acd80858..7a32ded565d 100644 --- a/runtime/src/main/kotlin/kotlin/text/Strings.kt +++ b/runtime/src/main/kotlin/kotlin/text/Strings.kt @@ -640,10 +640,6 @@ public fun String.replaceBeforeLast(delimiter: String, replacement: String, miss return if (index == -1) missingDelimiterValue else replaceRange(0, index, replacement) } - -// public fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean): String // JVM- and JS-specific -// public fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean): String // JVM- and JS-specific - /** * Returns a new string obtained by replacing each substring of this char sequence that matches the given regular expression * with the given [replacement].