diff --git a/libraries/stdlib/js/src/kotlin/text/charJs.kt b/libraries/stdlib/js/src/kotlin/text/charJs.kt index deec03b7d2d..5577d6be777 100644 --- a/libraries/stdlib/js/src/kotlin/text/charJs.kt +++ b/libraries/stdlib/js/src/kotlin/text/charJs.kt @@ -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. * * @sample samples.text.Chars.isWhitespace diff --git a/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt b/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt index d54c7a741c7..f78a968b3f2 100644 --- a/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/text/CharJVM.kt @@ -90,7 +90,12 @@ public inline fun Char.isJavaIdentifierPart(): Boolean = Character.isJavaIdentif 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. * * @sample samples.text.Chars.isWhitespace diff --git a/libraries/stdlib/native-wasm/src/kotlin/text/Char.kt b/libraries/stdlib/native-wasm/src/kotlin/text/Char.kt index 88b08a35ce4..37f1d1d2d08 100644 --- a/libraries/stdlib/native-wasm/src/kotlin/text/Char.kt +++ b/libraries/stdlib/native-wasm/src/kotlin/text/Char.kt @@ -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. * * @sample samples.text.Chars.isWhitespace diff --git a/libraries/stdlib/src/kotlin/text/Char.kt b/libraries/stdlib/src/kotlin/text/Char.kt index 88a5338b97a..c2008be79a2 100644 --- a/libraries/stdlib/src/kotlin/text/Char.kt +++ b/libraries/stdlib/src/kotlin/text/Char.kt @@ -335,7 +335,12 @@ public expect fun Char.isTitleCase(): 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. * * @sample samples.text.Chars.isWhitespace diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index a6069dce346..11c5f2c50ea 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -304,7 +304,7 @@ public inline fun CharSequence.isEmpty(): 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 */ diff --git a/libraries/stdlib/test/text/CharTest.kt b/libraries/stdlib/test/text/CharTest.kt index 6207b56be02..519becb4bc1 100644 --- a/libraries/stdlib/test/text/CharTest.kt +++ b/libraries/stdlib/test/text/CharTest.kt @@ -17,6 +17,8 @@ class CharTest { "Κκϰ", "Ππϖ", "Ρρϱ", "Σςσ", "Φφϕ", "ΩωΩ", "Ṡṡẛ", "Θθϑϴ", "Iiİı", ) + + val allCharsByCategory = (Char.MIN_VALUE..Char.MAX_VALUE).groupBy { it.category } } @Test @@ -326,6 +328,17 @@ class CharTest { 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 fun lowercaseChar() { assertEquals('\u0000', '\u0000'.lowercaseChar())