Interface

interface UnicodeExtension

public interface UnicodeExtension

Description: Specifies a Unicode character set extension interface, which is used to extend Unicode character set operations for other types.

It can be used to add a series of extended functions related to Unicode character sets for the Rune and String types, including character type determination, character case conversion, and whitespace character deletion.

extend Rune <: UnicodeExtension

extend Rune <: UnicodeExtension

Parent Type:

func isLetter()

public func isLetter(): Bool

Description: Checks whether a character is a Unicode alphabetic character.

Returns:

  • Bool: If the character is a Unicode alphabetic character, true is returned; otherwise, false is returned.

Example:

import std.unicode.*

main(): Unit {
    println(r'a'.isLetter())
    println(r'1'.isLetter())
}

Running result:

true
false

func isLowerCase()

public func isLowerCase(): Bool

Description: Checks whether the character is in Unicode lowercase.

Returns:

  • Bool: If the character is a Unicode lowercase character, true is returned; otherwise, false is returned.

Example:

import std.unicode.*

main(): Unit {
    println(r'a'.isLowerCase())
    println(r'A'.isLowerCase())
}

Running result:

true
false

func isNumber()

public func isNumber(): Bool

Description: Checks whether the character is a Unicode numeric character.

Returns:

  • Bool: If the character is a Unicode numeric character, true is returned; otherwise, false is returned.

Example:

import std.unicode.*

main(): Unit {
    println(r'a'.isNumber())
    println(r'1'.isNumber())
}

Running result:

false
true

func isTitleCase()

public func isTitleCase(): Bool

Description: Determines whether a character is a Unicode title character.

Title characters in Unicode refer to a special letter form, which is used to indicate the capitalization of the first letter of each word in a title in some languages. These letters are represented by special characters, for example, U+01C5 (Dž) and U+01F1 (DZ). These characters are usually used in some Eastern European languages, such as Croatian and Serbian.

Title characters include: 0x01C5, 0x01C8, 0x01CB, 0x01F2, 0x1F88 - 0x1F8F, 0x1F98 - 0x1F9F, 0x1F98 - 0x1F9F, 0x1FA8 - 0x1FAF, 0x1FBC, 0x1FCC, and 0x1FFC.

Returns:

  • Bool: If the character is a Unicode title uppercase character, true is returned; otherwise, false is returned.

Example:

import std.unicode.*

main(): Unit {
    println(r'Dž'.isTitleCase())
}

Running result:

true

func isUpperCase()

public func isUpperCase(): Bool

Description: Determines whether a character is a Unicode uppercase character.

Returns:

  • Bool: If the character is a Unicode uppercase character, true is returned; otherwise, false is returned.

Example:

import std.unicode.*

main(): Unit {
    println(r'a'.isUpperCase())
    println(r'A'.isUpperCase())
}

Running result:

false
true

func isWhiteSpace()

public func isWhiteSpace(): Bool

Description: Checks whether a character is a Unicode whitespace character.

Whitespace characters include 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0, 0X1680, 0X2000, 0X2001, 0X2002, 0X2003, 0X2004, 0X2005, 0X2006, 0X2007, 0X2008, 0X2009, 0X200A, 0X2028, 0X2029, 0X202F, 0X205F, and 0X3000.

Returns:

  • Bool: If the character is a Unicode whitespace character, true is returned; otherwise, false is returned.

Example:

import std.unicode.*

main(): Unit {
    println(r' '.isWhiteSpace())
}

Running result:

true

func toLowerCase()

public func toLowerCase(): Rune

Description: Obtains the Unicode lowercase character corresponding to the character.

Returns:

  • Rune: lowercase character corresponding to the current character

Example:

import std.unicode.*

main(): Unit {
    println(r'A'.toLowerCase())
}

Running result:

a

func toTitleCase()

public func toTitleCase(): Rune

Description: Obtains the Unicode title uppercase character corresponding to the character.

Returns:

  • Rune: title uppercase character corresponding to the current character

Example:

import std.unicode.*

main(): Unit {
    println(r'a'.toTitleCase())
}

Running result:

A

func toUpperCase()

public func toUpperCase(): Rune

Description: Obtains the Unicode uppercase letter corresponding to a character.

Returns:

  • Rune: lowercase character corresponding to the current character

Example:

import std.unicode.*

main(): Unit {
    println(r'a'.toUpperCase())
}

Running result:

A

extend String <: UnicodeExtension

extend String <: UnicodeExtension

Parent Type:

func isBlank()

public func isBlank(): Bool

Description: Checks whether the current string is empty or contains only null characters in the Unicode character set.

Whitespace characters include 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0, 0X1680, 0X2000, 0X2001, 0X2002, 0X2003, 0X2004, 0X2005, 0X2006, 0X2007, 0X2008, 0X2009, 0X200A, 0X2028, 0X2029, 0X202F, 0X205F, and 0X3000.

Returns:

  • Bool: If the string is null or contains only null characters, true is returned; otherwise, false is returned.

Example:

import std.unicode.*

main(): Unit {
    println(" \t\n\r".isBlank())
}

Running result:

true

func toLower()

public func toLower(): String

Description: Converts uppercase characters in all Unicode character sets of the current string to lowercase characters.

Returns:

  • String: all-lowercase string after conversion

Throws:

Example:

import std.unicode.*

main(): Unit {
    println("AbcDEF".toLower())
}

Running result:

abcdef

func toTitle()

public func toTitle(): String

Description: Converts the title uppercase characters in the Unicode character set of the current string to title uppercase characters.

Returns:

  • String: title capitalized string after conversion

Throws:

Example:

import std.unicode.*

main(): Unit {
    println("AbcDEF".toTitle())
}

Running result:

ABCDEF

func toUpper()

public func toUpper(): String

Description: Converts lowercase characters in all Unicode character sets of the current string to uppercase characters.

Returns:

  • String: all-uppercase string after conversion

Throws:

Example:

import std.unicode.*

main(): Unit {
    println("AbcDEF".toUpper())
}

Running result:

ABCDEF

func trim()

public func trim(): String

Description: Removes the substring consisting of null characters at the beginning and end of the original string. For the definition of null characters, see the extended function isWhiteSpace of the Rune type.

Returns:

  • String: Character string after the null characters at the beginning and the end are removed.

Throws:

Example:

import std.unicode.*

main(): Unit {
    println("\nx \t ".trim())
}

Running result:

x

func trimLeft()

public func trimLeft(): String

Description: Removes the substring consisting of null characters at the beginning of the original string. For the definition of null characters, see the extended function isWhiteSpace of the Rune type.

Returns:

  • String: Character string after the null character at the beginning is removed.

Throws:

Example:

import std.unicode.*

main(): Unit {
    println("  x  ".trimLeft())
}

Running result:

x

func trimRight()

public func trimRight(): String

Description: Removes the substring consisting of null characters at the end of the original string. For the definition of null characters, see the extended function isWhiteSpace of the Rune type.

Returns:

  • String: Character string after the null character at the end is removed.

Throws:

Example:

import std.unicode.*

main(): Unit {
    println("  x  ".trimRight())
}

Running result:

  x