Commonize CharCategory and related functions #KT-39177 #KT-43216 #KT-39906 #KT-30652

This commit is contained in:
Abduqodiri Qurbonzoda
2020-10-13 02:39:07 +03:00
parent 9b429fb535
commit 46b7a774b5
40 changed files with 3573 additions and 62 deletions
+85
View File
@@ -227,3 +227,88 @@ public fun Char.equals(other: Char, ignoreCase: Boolean = false): Boolean {
* Returns `true` if this character is a Unicode surrogate code unit.
*/
public fun Char.isSurrogate(): Boolean = this in Char.MIN_SURROGATE..Char.MAX_SURROGATE
/**
* Returns the Unicode general category of this character.
*/
public expect val Char.category: CharCategory
/**
* Returns `true` if this character (Unicode code point) is defined in Unicode.
*
* A character is considered to be defined in Unicode if its [category] is not [CharCategory.UNASSIGNED].
*/
public expect fun Char.isDefined(): Boolean
/**
* Returns `true` if this character is a letter.
*
* A character is considered to be a letter if its [category] is [CharCategory.UPPERCASE_LETTER],
* [CharCategory.LOWERCASE_LETTER], [CharCategory.TITLECASE_LETTER], [CharCategory.MODIFIER_LETTER], or [CharCategory.OTHER_LETTER].
*
* @sample samples.text.Chars.isLetter
*/
public expect fun Char.isLetter(): Boolean
/**
* Returns `true` if this character is a letter or digit.
*
* @see isLetter
* @see isDigit
*
* @sample samples.text.Chars.isLetterOrDigit
*/
public expect fun Char.isLetterOrDigit(): Boolean
/**
* Returns `true` if this character is a digit.
*
* A character is considered to be a digit if its [category] is [CharCategory.DECIMAL_DIGIT_NUMBER].
*
* @sample samples.text.Chars.isDigit
*/
public expect fun Char.isDigit(): Boolean
/**
* Returns `true` if this character is an upper case letter.
*
* A character is considered to be an upper case letter if its [category] is [CharCategory.UPPERCASE_LETTER].
*
* @sample samples.text.Chars.isUpperCase
*/
public expect fun Char.isUpperCase(): Boolean
/**
* Returns `true` if this character is a lower case letter.
*
* A character is considered to be a lower case letter if its [category] is [CharCategory.LOWERCASE_LETTER].
*
* @sample samples.text.Chars.isLowerCase
*/
public expect fun Char.isLowerCase(): Boolean
/**
* Returns `true` if this character is a title case letter.
*
* A character is considered to be a title case letter if its [category] is [CharCategory.TITLECASE_LETTER].
*
* @sample samples.text.Chars.isTitleCase
*/
public expect fun Char.isTitleCase(): Boolean
/**
* Returns `true` if this character is an ISO control character.
*
* A character is considered to be an ISO control character if its [category] is [CharCategory.CONTROL].
*
* @sample samples.text.Chars.isISOControl
*/
public expect fun Char.isISOControl(): Boolean
/**
* Determines whether a character is whitespace according to the Unicode standard.
* Returns `true` if the character is whitespace.
*
* @sample samples.text.Chars.isWhitespace
*/
public expect fun Char.isWhitespace(): Boolean
@@ -0,0 +1,171 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.text
/**
* Represents the character general category in the Unicode specification.
*/
public expect enum class CharCategory {
/**
* General category "Cn" in the Unicode specification.
*/
UNASSIGNED,
/**
* General category "Lu" in the Unicode specification.
*/
UPPERCASE_LETTER,
/**
* General category "Ll" in the Unicode specification.
*/
LOWERCASE_LETTER,
/**
* General category "Lt" in the Unicode specification.
*/
TITLECASE_LETTER,
/**
* General category "Lm" in the Unicode specification.
*/
MODIFIER_LETTER,
/**
* General category "Lo" in the Unicode specification.
*/
OTHER_LETTER,
/**
* General category "Mn" in the Unicode specification.
*/
NON_SPACING_MARK,
/**
* General category "Me" in the Unicode specification.
*/
ENCLOSING_MARK,
/**
* General category "Mc" in the Unicode specification.
*/
COMBINING_SPACING_MARK,
/**
* General category "Nd" in the Unicode specification.
*/
DECIMAL_DIGIT_NUMBER,
/**
* General category "Nl" in the Unicode specification.
*/
LETTER_NUMBER,
/**
* General category "No" in the Unicode specification.
*/
OTHER_NUMBER,
/**
* General category "Zs" in the Unicode specification.
*/
SPACE_SEPARATOR,
/**
* General category "Zl" in the Unicode specification.
*/
LINE_SEPARATOR,
/**
* General category "Zp" in the Unicode specification.
*/
PARAGRAPH_SEPARATOR,
/**
* General category "Cc" in the Unicode specification.
*/
CONTROL,
/**
* General category "Cf" in the Unicode specification.
*/
FORMAT,
/**
* General category "Co" in the Unicode specification.
*/
PRIVATE_USE,
/**
* General category "Cs" in the Unicode specification.
*/
SURROGATE,
/**
* General category "Pd" in the Unicode specification.
*/
DASH_PUNCTUATION,
/**
* General category "Ps" in the Unicode specification.
*/
START_PUNCTUATION,
/**
* General category "Pe" in the Unicode specification.
*/
END_PUNCTUATION,
/**
* General category "Pc" in the Unicode specification.
*/
CONNECTOR_PUNCTUATION,
/**
* General category "Po" in the Unicode specification.
*/
OTHER_PUNCTUATION,
/**
* General category "Sm" in the Unicode specification.
*/
MATH_SYMBOL,
/**
* General category "Sc" in the Unicode specification.
*/
CURRENCY_SYMBOL,
/**
* General category "Sk" in the Unicode specification.
*/
MODIFIER_SYMBOL,
/**
* General category "So" in the Unicode specification.
*/
OTHER_SYMBOL,
/**
* General category "Pi" in the Unicode specification.
*/
INITIAL_QUOTE_PUNCTUATION,
/**
* General category "Pf" in the Unicode specification.
*/
FINAL_QUOTE_PUNCTUATION;
/**
* Two-letter code of this general category in the Unicode specification.
*/
public val code: String
/**
* Returns `true` if [char] character belongs to this category.
*/
public operator fun contains(char: Char): Boolean
}