extend Byte <: ByteExtension
功能:为 Byte 类型实现一系列扩展方法,主要为在 Ascii 字符集范围内的一些字符判断、转换等操作。
func isAscii()
public func isAscii(): Bool
功能:判断 Byte 是否是在 Ascii 范围内。
返回值:
func isAsciiControl()
public func isAsciiControl(): Bool
功能:判断 Byte 是否是在 Ascii 控制字符范围内。其取值范围为 [00, 1F] 和 {7F} 的并集。
返回值:
func isAsciiGraphic()
public func isAsciiGraphic(): Bool
功能:判断 Byte 是否是在 Ascii 图形字符范围内。其取值范围为 [21, 7E]。
返回值:
func isAsciiHex()
public func isAsciiHex(): Bool
功能:判断 Byte 是否是在 Ascii 十六进制数字范围内。
返回值:
func isAsciiLetter()
public func isAsciiLetter(): Bool
功能:判断 Byte 是否是在 Ascii 拉丁字母范围内。
返回值:
func isAsciiLowerCase()
public func isAsciiLowerCase(): Bool
功能:判断 Byte 是否是在 Ascii 小写拉丁字母范围内。
返回值:
func isAsciiNumber()
public func isAsciiNumber(): Bool
功能:判断 Byte 是否是在 Ascii 十进制数字范围内。
返回值:
func isAsciiNumberOrLetter()
public func isAsciiNumberOrLetter(): Bool
功能:判断 Byte 是否是在 Ascii 十进制数字和拉丁字母范围内。
返回值:
func isAsciiOct()
public func isAsciiOct(): Bool
功能:判断 Byte 是否是在 Ascii 八进制数字范围内。
返回值:
func isAsciiPunctuation()
public func isAsciiPunctuation(): Bool
功能:判断 Byte 是否是在 Ascii 标点符号范围内。其取值范围为 [21, 2F]、[3A, 40]、[5B, 60] 和 [7B, 7E] 的并集。
返回值:
func isAsciiUpperCase()
public func isAsciiUpperCase(): Bool
功能:判断 Byte 是否是在 Ascii 大写拉丁字母范围内。
返回值:
func isAsciiWhiteSpace()
public func isAsciiWhiteSpace(): Bool
功能:判断 Byte 是否是在 Ascii 空白字符范围内。其取值范围为 [09, 0D] 和 {20} 的并集。
返回值:
func toAsciiLowerCase()
public func toAsciiLowerCase(): Byte
功能:将 Byte 换为对应的 Ascii 小写字符 Byte,如果无法转换则保持现状。
返回值:
func toAsciiUpperCase()
public func toAsciiUpperCase(): Byte
功能:将 Byte 换为对应的 Ascii 大写字符 Byte,如果无法转换则保持现状。
返回值:
sealed interface CType
功能:表示支持与 C 语言互操作的接口。
CType 接口是一个语言内置的空接口,它是 CType 约束的具体实现,所有 C 互操作支持的类型都隐式地实现了该接口,因此所有 C 互操作支持的类型都可以作为 CType 类型的子类型使用。
示例:
@C
struct Data {}
@C
func foo() {}
main() {
var c: CType = Data() // ok
c = 0 // ok
c = true // ok
c = CString(CPointer<UInt8>()) // ok
c = CPointer<Int8>() // ok
c = foo // ok
} public interface Collection<T> <: Iterable<T> {
prop size: Int64
func isEmpty(): Bool
func toArray(): Array<T>
} 功能:该接口用来表示集合,通常容器类型应该实现该接口。
public interface Comparable<T> <: Equatable<T> & Less<T> & Greater<T> & LessOrEqual<T> & GreaterOrEqual<T> {
func compare(that: T): Ordering
} 功能:该接口表示比较运算,是等于、小于、大于、小于等于、大于等于接口的集合体。
func compare(that: T): Ordering
功能:判断当前 T 类型实例与参数指向的 T 类型实例的大小关系。
参数:
返回值:
public interface Countable<T> {
func next(right: Int64): T
func position(): Int64
} 功能:该接口表示类型可数。
可数类型的每一个实例都对应一个位置信息(Int64 值),可以通过往后数数得到其他的该类型实例。
func next(right: Int64): T
功能:获取当前实例往右数 right 后所到位置的 T 类型实例。
参数:
返回值:
operator func ==(rhs: T): Bool
功能:判断两个实例是否相等。
参数:
返回值:
public interface Equatable<T> <: Equal<T> & NotEqual<T>
功能:该接口是判等和判不等两个接口的集合体。
已为部分仓颉类型实现该接口,包括:Unit、Bool 、Rune、Int64、Int32、Int16、Int8、UIntNative、UInt64、UInt32、UInt16、UInt8、Float64、Float32、Float16、String、Array、Box、ArrayList、HashSet。
public interface GreaterOrEqual<T> {
operator func >=(rhs: T): Bool
} 功能:该接口表示大于等于计算。
operator func >=(rhs: T): Bool
功能:判断当前 T 类型实例是否大于等于参数指向的 T 类型实例。
参数:
返回值:
operator func >(rhs: T): Bool
功能:判断当前 T 类型实例是否大于参数指向的 T 类型实例。
参数:
返回值:
public interface Hashable {
func hashCode(): Int64
} 功能:该接口用于计算哈希值。
已为部分仓颉类型实现该接口,包括:Bool、Rune、IntNative、Int64、Int32、Int16、Int8、UIntNative、UInt64、UInt32、UInt16、UInt8、Float64、Float32、Float16、String、Box。
public interface Hasher {
func finish(): Int64
mut func reset(): Unit
mut func write(value: Bool): Unit
mut func write(value: Rune): Unit
mut func write(value: Int8): Unit
mut func write(value: Int16): Unit
mut func write(value: Int32): Unit
mut func write(value: Int64): Unit
mut func write(value: UInt8): Unit
mut func write(value: UInt16): Unit
mut func write(value: UInt32): Unit
mut func write(value: UInt64): Unit
mut func write(value: Float16): Unit
mut func write(value: Float32): Unit
mut func write(value: Float64): Unit
mut func write(value: String): Unit
} 功能:该接口用于处理哈希组合运算。
可以使用一系列 write 函数传入不同数据类型实例,并计算他们的组合哈希值。
mut func write(value: Bool): Unit
功能:把想要哈希运算的 Bool 值传入,然后进行哈希组合运算。
参数:
mut func write(value: Float16): Unit
功能:通过该函数把想要哈希运算的 Float16 值传入,然后进行哈希组合运算。
参数:
mut func write(value: Float32): Unit
功能:通过该函数把想要哈希运算的 Float32 值传入,然后进行哈希组合运算。
参数:
mut func write(value: Float64): Unit
功能:通过该函数把想要哈希运算的 Float64 值传入,然后进行哈希组合运算。
参数:
mut func write(value: Int16): Unit
功能:通过该函数把想要哈希运算的 Int16 值传入,然后进行哈希组合运算。
参数:
mut func write(value: Int32): Unit
功能:通过该函数把想要哈希运算的 Int32 值传入,然后进行哈希组合运算。
参数:
mut func write(value: Int64): Unit
功能:通过该函数把想要哈希运算的 Int64 值传入,然后进行哈希组合运算。
参数:
mut func write(value: Int8): Unit
功能:通过该函数把想要哈希运算的 Int8 值传入,然后进行哈希组合运算。
参数:
mut func write(value: Rune): Unit
功能:通过该函数把想要哈希运算的 Rune 值传入,然后进行哈希组合运算。
参数:
mut func write(value: String): Unit
功能:通过该函数把想要哈希运算的 String 值传入,然后进行哈希组合运算。
参数:
mut func write(value: UInt16): Unit
功能:通过该函数把想要哈希运算的 UInt16 值传入,然后进行哈希组合运算。
参数:
mut func write(value: UInt32): Unit
功能:通过该函数把想要哈希运算的 UInt32 值传入,然后进行哈希组合运算。
参数:
mut func write(value: UInt64): Unit
功能:通过该函数把想要哈希运算的 UInt64 值传入,然后进行哈希组合运算。
参数:
mut func write(value: UInt8): Unit
功能:通过该函数把想要哈希运算的 UInt8 值传入,然后进行哈希组合运算。
参数:
public interface Iterable<E> {
func iterator(): Iterator<E>
} 功能:该接口表示可迭代,实现了该接口的类型(通常为容器类型)可以在 for-in 语句中实现迭代,也可以获取其对应的迭代器类型实例,调用 next 函数实现迭代。
本包已经为 Array、ArrayList、HashMap 等基础容器类型实现了该接口,用户可以为其他类型实现该接口,使之支持迭代遍历的功能。
public interface LessOrEqual<T> {
operator func <=(rhs: T): Bool
} 功能:该接口表示小于等于计算。
operator func <=(rhs: T): Bool
功能:判断当前 T 类型实例是否小于等于参数指向的 T 类型实例。
参数:
返回值:
operator func <(rhs: T): Bool
功能:判断当前 T 类型实例是否小于参数指向的 T 类型实例。
参数:
返回值:
public interface NotEqual<T> {
operator func !=(rhs: T): Bool
} 功能:该接口用于支持判不等操作。
operator func !=(rhs: T): Bool
功能:判断两个实例是否不相等。
参数:
返回值:
public interface Resource {
func close(): Unit
func isClosed(): Bool
} 功能:该接口用于资源管理,通常用于内存、句柄等资源的关闭和释放。
实现了该接口的类型可以在 try-with-resource 语法上下文中实现自动资源释放。
func close()
func close(): Unit
功能:关闭资源。
public interface ThreadContext {
func end(): Unit
func hasEnded(): Bool
} 功能:仓颉线程上下文接口。
用户创建 thread 时,除了缺省 spawn 表达式入参,也可以通过传入不同 ThreadContext 类型的实例,选择不同的线程上下文,然后一定程度上控制并发行为。
目前不允许用户自行实现 ThreadContext 接口,仓颉语言根据使用场景,提供了 MainThreadContext, 具体定义可在终端框架库中查阅。
func hasEnded(): Bool
功能:检查方法,用于检查当前 context 是否已结束。
返回值: