JS backend: added String.isEmpty
(cherry picked from commit 6cf1761)
This commit is contained in:
@@ -40,6 +40,8 @@ public val String.size: Int
|
||||
|
||||
public fun String.length(): Int = js.noImpl
|
||||
|
||||
public fun String.isEmpty(): Boolean = js.noImpl
|
||||
|
||||
/*
|
||||
|
||||
native public fun String.equalsIgnoreCase(anotherString: String) : Boolean = (this as java.lang.String).equalsIgnoreCase(anotherString)
|
||||
@@ -118,7 +120,7 @@ native public fun String.getBytes(charset : java.nio.charset.Charset) : ByteArra
|
||||
|
||||
native public fun String.getBytes(charsetName : String) : ByteArray = (this as java.lang.String).getBytes(charsetName)!!
|
||||
|
||||
native public fun String.getChars(srcBegin : Int, srcEnd : Int, dst : CharArray, dstBegin : Int) : Unit = (this as java.lang.String).getChars(srcBegin, srcEnd, dst, dstBegin)!!
|
||||
native public fun String.getChars(srcBegin : Int, srcEnd : Int, dst : CharArray, dstBegin : Int) : Tuple0 = (this as java.lang.String).getChars(srcBegin, srcEnd, dst, dstBegin)!!
|
||||
|
||||
native public fun String.intern() : String = (this as java.lang.String).intern()!!
|
||||
|
||||
|
||||
+18
@@ -16,9 +16,17 @@
|
||||
|
||||
package org.jetbrains.k2js.translate.intrinsic.functions.factories;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.BuiltInFunctionIntrinsic;
|
||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.BuiltInPropertyIntrinsic;
|
||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.FunctionIntrinsic;
|
||||
import org.jetbrains.k2js.translate.utils.JsAstUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.translate.intrinsic.functions.patterns.PatternBuilder.pattern;
|
||||
|
||||
@@ -34,5 +42,15 @@ public final class StringOperationFIF extends CompositeFIF {
|
||||
add(pattern("js", "<get-size>").receiverExists(true), lengthIntrinsic);
|
||||
add(pattern("js", "length").receiverExists(true), lengthIntrinsic);
|
||||
add(pattern("jet", "CharSequence", "<get-length>"), lengthIntrinsic);
|
||||
add(pattern("js", "isEmpty").receiverExists(true), new FunctionIntrinsic() {
|
||||
@NotNull
|
||||
@Override
|
||||
public JsExpression apply(
|
||||
@Nullable JsExpression receiver, @NotNull List<JsExpression> arguments, @NotNull TranslationContext context
|
||||
) {
|
||||
assert receiver != null;
|
||||
return JsAstUtils.equality(new JsNameRef("length", receiver), context.program().getNumberLiteral(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ package foo
|
||||
|
||||
fun box(): Boolean {
|
||||
val s = "bar"
|
||||
return s.size == 3 && s.length() == 3 && s.length == 3
|
||||
}
|
||||
return s.size == 3 && s.length() == 3 && s.length == 3 && s.startsWith("b") && s.endsWith("r") && s.contains("a") && !s.isEmpty()
|
||||
}
|
||||
Reference in New Issue
Block a user