Some work for string concatenation. (#40)

This commit is contained in:
Nikolay Igotti
2016-11-07 15:58:11 +03:00
committed by GitHub
parent 451ac00087
commit f06aeef9ce
9 changed files with 68 additions and 23 deletions
+6
View File
@@ -226,4 +226,10 @@ KInt Kotlin_String_hashCode(const ArrayHeader* thiz) {
return CityHash64(ByteArrayAddressOfElementAt(thiz, 0), thiz->count_);
}
KRef Kotlin_String_subSequence(
const ArrayHeader* thiz, KInt startIndex, KInt endIndex) {
RuntimeAssert(false, "Unsupported operation");
return nullptr;
}
} // extern "C"
+2
View File
@@ -91,6 +91,8 @@ ArrayHeader* Kotlin_String_fromUtf8Array(const ArrayHeader* array);
ArrayHeader* Kotlin_String_plusImpl(
const ArrayHeader* thiz, const ArrayHeader* other);
KInt Kotlin_String_getStringLength(const ArrayHeader* thiz);
KRef Kotlin_String_subSequence(
const ArrayHeader* thiz, KInt startIndex, KInt endIndex);
#ifdef __cplusplus
}
+2 -2
View File
@@ -2,8 +2,8 @@ package kotlin
@ExportTypeInfo("theAnyTypeInfo")
public open class Any {
// @SymbolName("Kotlin_Any_equals")
// external public open operator fun equals0(other: Any0?): Boolean
@SymbolName("Kotlin_Any_equals")
external public open operator fun equals(other: Any?): Boolean
// TODO: do we need that in Any?
@SymbolName("Kotlin_Any_hashCode")
@@ -0,0 +1,25 @@
package kotlin
/**
* Represents a readable sequence of [Char] values.
*/
public interface CharSequence {
/**
* Returns the length of this character sequence.
*/
public val length: Int
/**
* Returns the character at the specified [index] in this character sequence.
*/
public operator fun get(index: Int): Char
/**
* Returns a new character sequence that is a subsequence of this character sequence,
* starting at the specified [startIndex] and ending right before the specified [endIndex].
*
* @param startIndex the start index (inclusive).
* @param endIndex the end index (exclusive).
*/
public fun subSequence(startIndex: Int, endIndex: Int): CharSequence
}
+15 -10
View File
@@ -4,27 +4,32 @@ package kotlin
external fun fromUtf8Array(array: ByteArray) : String
@ExportTypeInfo("theStringTypeInfo")
class String {
class String : Comparable<String>/* , CharSequence */ {
@SymbolName("Kotlin_String_hashCode")
external public override fun hashCode(): Int
/* TODO: calling to virtual method (plusImpl) results in link error; uncomment after supporting
calling virtual methods in translator
public operator fun plus(other: Any?): String {
// TODO: make it Any?
public operator fun plus(other: Any): String {
return plusImpl(other.toString())
}
*/
public val length: Int
/*
public fun override toString(): String {
return this
} */
public /* override */ val length: Int
get() = getStringLength()
// Can be O(N).
@SymbolName("Kotlin_String_get")
external public fun get(index: Int): Char
external /* override */ public fun get(index: Int): Char
@SymbolName("Kotlin_String_subSequence")
external /* override */ public fun subSequence(startIndex: Int, endIndex: Int): CharSequence
// external public fun subSequence(startIndex: Int, endIndex: Int): CharSequence
@SymbolName("Kotlin_String_compareTo")
external public fun compareTo(other: String): Int
override external public fun compareTo(other: String): Int
@SymbolName("Kotlin_String_getStringLength")
external private fun getStringLength(): Int
@@ -33,5 +38,5 @@ calling virtual methods in translator
external private fun plusImpl(other:Any): String
@SymbolName("Kotlin_String_equals")
external public override operator fun equals(other: Any?): Boolean
external public override fun equals(other: Any?): Boolean
}
+1 -1
View File
@@ -1,5 +1,5 @@
package kotlin
public object Unit {
// override fun toString() = "kotlin.Unit"
override fun toString() = "kotlin.Unit"
}