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:
Alexander Udalov
2014-11-27 16:02:41 +03:00
parent 4d95bcfc7e
commit 8dae1b62dd
14 changed files with 64 additions and 21 deletions
@@ -90,4 +90,8 @@ public final class StringTest extends AbstractExpressionTest {
public void testNullableTypeInStringTemplate() throws Exception {
checkFooBoxIsOk();
}
public void testSubSequence() throws Exception {
checkFooBoxIsOk();
}
}
@@ -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"
}