From fe6268f4583595ebb24b7672a377d5585f39007a Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 7 Mar 2012 19:28:04 +0000 Subject: [PATCH] merged pull request https://github.com/JetBrains/kotlin/pull/12 from ntaro with thanks! --- libraries/stdlib/src/String.kt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libraries/stdlib/src/String.kt b/libraries/stdlib/src/String.kt index 6f6ac6540f0..9c5b9922e2d 100644 --- a/libraries/stdlib/src/String.kt +++ b/libraries/stdlib/src/String.kt @@ -164,4 +164,22 @@ inline fun String.toLowerCase(locale : java.util.Locale) = (this as java.lang.St inline fun String.toUpperCase(locale : java.util.Locale) = (this as java.lang.String).toUpperCase(locale).sure() /** Returns the string if it is not null or the empty string if its null */ -inline fun String?.orEmpty(): String = this ?: "" \ No newline at end of file +inline fun String?.orEmpty(): String = this ?: "" + + +// "Extension functions" for CharSequence + +inline fun CharSequence.length() = (this as java.lang.CharSequence).length() + +inline val CharSequence.size : Int +get() = length() + +inline fun CharSequence.charAt(index : Int) = (this as java.lang.CharSequence).charAt(index) + +inline fun CharSequence.get(index : Int) = charAt(index) + +inline fun CharSequence.subSequence(start : Int, end : Int) = (this as java.lang.CharSequence).subSequence(start, end) + +inline fun CharSequence.get(start : Int, end : Int) = subSequence(start, end) + +inline fun CharSequence.toString() = (this as java.lang.CharSequence).toString() \ No newline at end of file