Add CharSequence.subSequence
This is done primarily for JVM interoperability, otherwise it's impossible to inherit from CharSequence there. On JS subSequence at the moment just invokes substring. #KT-5956 Fixed
This commit is contained in:
@@ -90,4 +90,8 @@ public final class StringTest extends AbstractExpressionTest {
|
||||
public void testNullableTypeInStringTemplate() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSubSequence() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -30,6 +30,7 @@ public final class StringOperationFIF extends CompositeFIF {
|
||||
// This intrinsic is needed because charAt is a public function taking one parameter and thus its name would be mangled otherwise
|
||||
add(pattern("kotlin", "CharSequence", "charAt").checkOverridden(), new BuiltInFunctionIntrinsic("charAt"));
|
||||
add(pattern("kotlin", "CharSequence", "length").checkOverridden(), LENGTH_PROPERTY_INTRINSIC);
|
||||
add(pattern("kotlin", "CharSequence", "subSequence").checkOverridden(), new BuiltInFunctionIntrinsic("substring"));
|
||||
add(pattern("kotlin.js", "isEmpty").isExtensionOf("kotlin.CharSequence"), IS_EMPTY_INTRINSIC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val kotlin: String = "kotlin"
|
||||
|
||||
if (kotlin.subSequence(0, kotlin.length()) != kotlin) return "Fail 0"
|
||||
|
||||
val kot: CharSequence = kotlin.subSequence(0, 3)
|
||||
if (kot.toString() != "kot") return "Fail 1: $kot"
|
||||
|
||||
val tlin = (kotlin : CharSequence).subSequence(2, 6)
|
||||
if (tlin.toString() != "tlin") return "Fail 2: $tlin"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user