merged pull request https://github.com/JetBrains/kotlin/pull/12 from ntaro with thanks!

This commit is contained in:
James Strachan
2012-03-07 19:28:04 +00:00
parent 7afe9e6fcf
commit fe6268f458
+19 -1
View File
@@ -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 ?: ""
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()