[stdlib] Improve documentation of Char.isWhitespace and test it behaves the same in different targets
This commit is contained in:
committed by
Space Team
parent
baca742a31
commit
709076acc9
@@ -247,7 +247,12 @@ public actual fun Char.isISOControl(): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether a character is whitespace according to the Unicode standard.
|
* Determines whether a character is whitespace.
|
||||||
|
*
|
||||||
|
* A character is considered whitespace if either its Unicode [category][Char.category]
|
||||||
|
* is one of [CharCategory.SPACE_SEPARATOR], [CharCategory.LINE_SEPARATOR], [CharCategory.PARAGRAPH_SEPARATOR],
|
||||||
|
* or it is a [CharCategory.CONTROL] character in range `U+0009..U+000D` or `U+001C..U+001F`.
|
||||||
|
*
|
||||||
* Returns `true` if the character is whitespace.
|
* Returns `true` if the character is whitespace.
|
||||||
*
|
*
|
||||||
* @sample samples.text.Chars.isWhitespace
|
* @sample samples.text.Chars.isWhitespace
|
||||||
|
|||||||
@@ -90,7 +90,12 @@ public inline fun Char.isJavaIdentifierPart(): Boolean = Character.isJavaIdentif
|
|||||||
public inline fun Char.isJavaIdentifierStart(): Boolean = Character.isJavaIdentifierStart(this)
|
public inline fun Char.isJavaIdentifierStart(): Boolean = Character.isJavaIdentifierStart(this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether a character is whitespace according to the Unicode standard.
|
* Determines whether a character is whitespace.
|
||||||
|
*
|
||||||
|
* A character is considered whitespace if either its Unicode [category][Char.category]
|
||||||
|
* is one of [CharCategory.SPACE_SEPARATOR], [CharCategory.LINE_SEPARATOR], [CharCategory.PARAGRAPH_SEPARATOR],
|
||||||
|
* or it is a [CharCategory.CONTROL] character in range `U+0009..U+000D` or `U+001C..U+001F`.
|
||||||
|
*
|
||||||
* Returns `true` if the character is whitespace.
|
* Returns `true` if the character is whitespace.
|
||||||
*
|
*
|
||||||
* @sample samples.text.Chars.isWhitespace
|
* @sample samples.text.Chars.isWhitespace
|
||||||
|
|||||||
@@ -74,7 +74,12 @@ public actual fun Char.isDigit(): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether a character is whitespace according to the Unicode standard.
|
* Determines whether a character is whitespace.
|
||||||
|
*
|
||||||
|
* A character is considered whitespace if either its Unicode [category][Char.category]
|
||||||
|
* is one of [CharCategory.SPACE_SEPARATOR], [CharCategory.LINE_SEPARATOR], [CharCategory.PARAGRAPH_SEPARATOR],
|
||||||
|
* or it is a [CharCategory.CONTROL] character in range `U+0009..U+000D` or `U+001C..U+001F`.
|
||||||
|
*
|
||||||
* Returns `true` if the character is whitespace.
|
* Returns `true` if the character is whitespace.
|
||||||
*
|
*
|
||||||
* @sample samples.text.Chars.isWhitespace
|
* @sample samples.text.Chars.isWhitespace
|
||||||
|
|||||||
@@ -335,7 +335,12 @@ public expect fun Char.isTitleCase(): Boolean
|
|||||||
public expect fun Char.isISOControl(): Boolean
|
public expect fun Char.isISOControl(): Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether a character is whitespace according to the Unicode standard.
|
* Determines whether a character is whitespace.
|
||||||
|
*
|
||||||
|
* A character is considered whitespace if either its Unicode [category][Char.category]
|
||||||
|
* is one of [CharCategory.SPACE_SEPARATOR], [CharCategory.LINE_SEPARATOR], [CharCategory.PARAGRAPH_SEPARATOR],
|
||||||
|
* or it is a [CharCategory.CONTROL] character in range `U+0009..U+000D` or `U+001C..U+001F`.
|
||||||
|
*
|
||||||
* Returns `true` if the character is whitespace.
|
* Returns `true` if the character is whitespace.
|
||||||
*
|
*
|
||||||
* @sample samples.text.Chars.isWhitespace
|
* @sample samples.text.Chars.isWhitespace
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ public inline fun CharSequence.isEmpty(): Boolean = length == 0
|
|||||||
public inline fun CharSequence.isNotEmpty(): Boolean = length > 0
|
public inline fun CharSequence.isNotEmpty(): Boolean = length > 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if this char sequence is empty or consists solely of whitespace characters.
|
* Returns `true` if this char sequence is empty or consists solely of whitespace characters according to [Char.isWhitespace].
|
||||||
*
|
*
|
||||||
* @sample samples.text.Strings.stringIsBlank
|
* @sample samples.text.Strings.stringIsBlank
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class CharTest {
|
|||||||
"Κκϰ", "Ππϖ", "Ρρϱ", "Σςσ", "Φφϕ", "ΩωΩ", "Ṡṡẛ",
|
"Κκϰ", "Ππϖ", "Ρρϱ", "Σςσ", "Φφϕ", "ΩωΩ", "Ṡṡẛ",
|
||||||
"Θθϑϴ", "Iiİı",
|
"Θθϑϴ", "Iiİı",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val allCharsByCategory = (Char.MIN_VALUE..Char.MAX_VALUE).groupBy { it.category }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -326,6 +328,17 @@ class CharTest {
|
|||||||
assertEquals("Cc", CharCategory.CONTROL.code)
|
assertEquals("Cc", CharCategory.CONTROL.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun whitespace() {
|
||||||
|
val allWhitespace = (Char.MIN_VALUE..Char.MAX_VALUE).filter { it.isWhitespace() }
|
||||||
|
val expected =
|
||||||
|
listOf(CharCategory.SPACE_SEPARATOR, CharCategory.LINE_SEPARATOR, CharCategory.PARAGRAPH_SEPARATOR)
|
||||||
|
.flatMap { allCharsByCategory[it]!! } +
|
||||||
|
('\u0009'..'\u000D') +
|
||||||
|
('\u001C'..'\u001F')
|
||||||
|
assertEquals(expected.sorted(), allWhitespace)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun lowercaseChar() {
|
fun lowercaseChar() {
|
||||||
assertEquals('\u0000', '\u0000'.lowercaseChar())
|
assertEquals('\u0000', '\u0000'.lowercaseChar())
|
||||||
|
|||||||
Reference in New Issue
Block a user