KT-4614: Add String.format(Locale, args)
This commit is contained in:
committed by
Andrey Breslav
parent
d54fb97c5d
commit
a3ad79e5d9
@@ -5,6 +5,7 @@ import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
import java.util.LinkedList
|
||||
import java.util.Locale
|
||||
import java.nio.charset.Charset
|
||||
|
||||
public inline fun String.lastIndexOf(str: String) : Int = (this as java.lang.String).lastIndexOf(str)
|
||||
@@ -39,6 +40,8 @@ public fun String.toCharList(): List<Char> = toCharArray().toList()
|
||||
|
||||
public inline fun String.format(vararg args : Any?) : String = java.lang.String.format(this, *args)
|
||||
|
||||
public inline fun String.format(locale: Locale, vararg args : Any?) : String = java.lang.String.format(locale, this, *args)
|
||||
|
||||
public inline fun String.split(regex : String) : Array<String> = (this as java.lang.String).split(regex)
|
||||
|
||||
public inline fun String.split(ch : Char) : Array<String> = (this as java.lang.String).split(java.util.regex.Pattern.quote(ch.toString()))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package test.text
|
||||
|
||||
import java.util.Locale
|
||||
import kotlin.test.*
|
||||
|
||||
import org.junit.Test as test
|
||||
@@ -275,6 +276,10 @@ class StringJVMTest {
|
||||
|
||||
test fun formatter() {
|
||||
assertEquals("12", "%d%d".format(1, 2))
|
||||
|
||||
assertEquals("1,234,567.890", "%,.3f".format(Locale.ENGLISH, 1234567.890))
|
||||
assertEquals("1.234.567,890", "%,.3f".format(Locale.GERMAN, 1234567.890))
|
||||
assertEquals("1 234 567,890", "%,.3f".format(Locale("fr"), 1234567.890))
|
||||
}
|
||||
|
||||
test fun trimLeading() {
|
||||
|
||||
Reference in New Issue
Block a user