std.core
Function Description
The core package provides some basic API capabilities applicable to Cangjie programming.
Built-in types (such as signed integer, unsigned integer, and floating-point number), common functions (such as print, println, and eprint), common interfaces (such as ToString, Hashable, Equatable, and Collection), common classes and structs (such as Array, String, and Range), and common exception classes (such as Error, Exception, and their subclasses) are provided.
NOTE
The core package is imported by default.
API List
Function
| Name | Description |
|---|---|
| acquireArrayRawData(Array<T>) where T <: CType | Obtains an original pointer instance of data in Array |
| alignOf<T>() where T <: CType | Obtains the memory alignment value of T type. |
| eprint(String, Bool) | Prints the specified string to the standard error text stream. |
| eprintln(String) | Prints the specified string (with a newline character at the end) to the standard error text stream. |
| eprint<T>(T, Bool) where T <: ToString | Prints the string representation of a specified instance of the T type to the standard error text stream. |
| eprintln<T>(T) where T <: ToString | Prints the string representation (with a newline character at the end) of a specified instance of the T type to the standard error text stream. |
| ifNone(Option<T>, () -> Unit) | If data of the Option.None type is input, the action function is executed. |
| ifSome(Option<T>, (T) -> Unit) | If data of the Option.Some type is input, the action function is executed. |
| max<T>(T, T, Array<T>) where T <: Comparable<T> | Obtains the maximum value in a data set. |
| min<T>(T, T, Array<T>) where T <: Comparable<T> | Obtains the minimum value in a data set. |
| print(Bool, Bool) | Outputs the string representation of data of the Bool type to the console. |
| print(Float16, Bool) | Outputs the string representation of data of the Float16 type to the console. |
| print(Float32, Bool) | Outputs the string representation of data of the Float32 type to the console. |
| print(Float64, Bool) | Outputs the string representation of data of the Float64 type to the console. |
| print(Int16, Bool) | Outputs the string representation of data of the Int16 type to the console. |
| print(Int32, Bool) | Outputs the string representation of data of the Int32 type to the console. |
| print(Int64, Bool) | Outputs the string representation of data of the Int64 type to the console. |
| print(Int8, Bool) | Outputs the string representation of data of the Int8 type to the console. |
| print(Rune, Bool) | Outputs the string representation of data of the Rune type to the console. |
| print(String, Bool) | Outputs a specified string to the console. |
| print(UInt16, Bool) | Outputs the string representation of data of the UInt16 type to the console. |
| print(UInt32, Bool) | Outputs the string representation of data of the UInt32 type to the console. |
| print(UInt64, Bool) | Outputs the string representation of data of the UInt64 type to the console. |
| print(UInt8, Bool) | Outputs the string representation of data of the UInt8 type to the console. |
| print<T>(T, Bool) where T <: ToString | Outputs the string representation of an instance of the T type to the console. |
| println() | Outputs a newline character to the standard output (stdout). |
| println(Bool) | Outputs the string representation (with a newline character at the end) of data of the Bool type to the console. |
| println(Float16) | Outputs the string representation (with a newline character at the end) of data of the Float16 type to the console. |
| println(Float32) | Outputs the string representation (with a newline character at the end) of data of the Float32 type to the console. |
| println(Float64) | Outputs the string representation (with a newline character at the end) of data of the Float64 type to the console. |
| println(Int16) | Outputs the string representation (with a newline character at the end) of data of the Int16 type to the console. |
| println(Int32) | Outputs the string representation (with a newline character at the end) of data of the Int32 type to the console. |
| println(Int64) | Outputs the string representation (with a newline character at the end) of data of the Int64 type to the console. |
| println(Int8) | Outputs the string representation (with a newline character at the end) of data of the Int8 type to the console. |
| println(Rune) | Outputs the string representation (with a newline character at the end) of data of the Rune type to the console. |
| println(String) | Outputs a specified string (with a newline character at the end) to the console. |
| println(UInt16) | Outputs the string representation (with a newline character at the end) of data of the UInt16 type to the console. |
| println(UInt32) | Outputs the string representation (with a newline character at the end) of data of the UInt32 type to the console. |
| println(UInt64) | Outputs the string representation (with a newline character at the end) of data of the UInt64 type to the console. |
| println(UInt8) | Outputs the string representation (with a newline character at the end) of data of the UInt8 type to the console. |
| println<T>(T) where T <: ToString | Outputs the string representation (with a newline character at the end) of instance of the T type to the console. |
| readln() | Receives the console input until the newline or end of file (EOF). |
| refEq(Object, Object) | Checks whether the memory addresses of two Object instances are the same. |
| releaseArrayRawData(CPointerHandle<T>) where T <: CType | Releases an original pointer instance obtained using acquireArrayRawData. |
| sizeOf<T>() where T <: CType | Obtains the memory space occupied by the T type. |
| sleep(Duration) | Hibernates the current thread. |
| zeroValue<T>() | Obtains a T-type instance that has been subject to zero initialization. |
Type Alias
| Name | Description |
|---|---|
| Byte | The Byte type is the alias of the built-in UInt8 type. |
| Int | The Int type is the alias of the built-in Int64 type. |
| UInt | The UInt type is the alias of the built-in UInt64 type. |
Built-in Type
| Name | Description |
|---|---|
| Int8 | Represents an 8-bit signed integer ranging from –2^7 to 2^7 – 1. |
| Int16 | Represents a 16-bit signed integer ranging from –2^{15} to 2^{15} – 1. |
| Int32 | Represents a 32-bit signed integer ranging from –2^{31} to 2^{31} – 1. |
| Int64 | Represents a 64-bit signed integer ranging from –2^{63} to 2^{63} – 1. |
| IntNative | Represents a platform-related signed integer with the length same as the bit width of the current system. |
| UInt8 | Represents an 8-bit unsigned integer ranging from 0 to 2^8-1. |
| UInt16 | Represents a 16-bit unsigned integer ranging from 0 to 2^{16}-1. |
| UInt32 | Represents a 32-bit unsigned integer ranging from 0 to 2^{32}-1. |
| UInt64 | Represents a 64-bit unsigned integer ranging from 0 to 2^{64}-1. |
| UIntNative | Represents a platform-related unsigned integer with the length same as the bit width of the current system. |
| Float16 | Represents a 16-bit floating-point number complying with the half-precision format (binary16) specified in IEEE 754. |
| Float32 | Represents a 32-bit floating-point number complying with the single-precision format (binary32) specified in IEEE 754. |
| Float64 | Represents a 64-bit floating-point number complying with the double-precision format (binary64) specified in IEEE 754. |
| Bool | Represents the Boolean type. The value options are true and false. |
| Rune | Represents the characters in the Unicode character set. |
| Unit | Represents the type of an expression that concerns only side effects but not values in the Cangjie language. |
| CPointer<T> | Indicates the pointer to the instance of the T type. It corresponds to T* of the C language in the scenario where the C language is used. |
| CString | Represents the C-style string, which is used in the scenario where the C language is used. |
Interface
| Name | Description |
|---|---|
| Any | Specifies the parent type of all types. By default, all interface types inherit Any and all non-interface types implement Any. |
| Hasher | Processes combined hash operations. |
| ThreadContext | Specifies a Cangjie thread context interface. |
| Countable<T> | Indicates a countable type. |
| Collection<T> | Indicates a collection. Generally, a container type should implement this interface. |
| Less<T> | Supports calculations with the result indicating whether one instance is less than the other instance or not. |
| Greater<T> | Supports calculations with the result indicating whether one instance is greater than the other instance or not. |
| LessOrEqual<T> | Supports calculations with the result indicating whether one instance is less than or equal to the other instance or not. |
| GreaterOrEqual<T> | Supports calculations with the result indicating whether one instance is greater than or equal to the other instance or not. |
| Comparable<T> | Indicates comparison operation. This interface is a collection of interfaces indicating equal to, less than, greater than, less than or equal to, and greater than or equal to. |
| Equal<T> | Supports equality check. |
| NotEqual<T> | Supports inequality check. |
| Equatable<T> | Specifies a collection of the equality check and inequality check interfaces. |
| Hashable | Calculates hash values. |
| Iterable<E> | Supports iteration. A type (usually the container type) that implements this interface can be iterated in the for-in statement. Alternatively, such type can be iterated by calling the next function based on the corresponding iterator type instance. |
| Resource | Manages resources, such as closing and releasing memory and handles. |
| ToString | Provides the string representation of a specific type. |
| CType | Indicates the interface that supports interoperability with the C language. |
Class
| Name | Description |
|---|---|
| ArrayIterator<T> | Specifies an array iterator. For details about its functions, see the description of Iterable and Iterator. |
| Box<T> | Provides the capability of adding a layer of class encapsulation to other types. |
| Future<T> | Represents a Cangjie thread task. It can be used to obtain the calculation result of a Cangjie thread and send a cancellation signal to the Cangjie thread. |
| Iterator<T> | Indicates an iterator and provides the next method to support iterative traversal of members in a container. |
| Object | Constructs an object instance. |
| RangeIterator<T> <: Iterator<T> where T <: Countable<T> & Comparable<T> & Equatable<T> | Specifies an iterator of the Range type. For details about its functions, see the description of Iterable and Iterator. |
| StackTraceElement | Indicates the detailed information about an exception stack, including the class name, function name, file name, and line number involved in the exception. |
| StringBuilder | Constructs strings. |
| Thread | Represents a Cangjie class, which can be used to obtain thread IDs and names, check whether a thread receives any cancellation request, and register processing functions for exceptions not handled by threads. |
| ThreadLocal<T> | Indicates a Cangjie thread local variable. |
Enumeration
| Name | Description |
|---|---|
| AnnotationKind | Indicates the location that the custom annotation is expected to support. |
| Endian | Indicates the endianness of the running platform, which can be big endian or little endian. |
| Ordering | Indicates a comparison result and includes three situations: less than, greater than, and equal to. |
| Option<T> | Encapsulates the T type, indicating that the type may or may not have a value. |
Struct
| Name | Description |
|---|---|
| Array<T> | Specifies a Cangjie array type used to represent an ordered sequence consisting of elements of a single type. |
| CPointerHandle<T> where T <: CType | Indicates the original pointer of Array. Generic parameters in this type must meet the CType constraint. |
| CPointerResource<T> where T <: CType | Indicates the resource management type corresponding to CPointer. Instances of this type can be obtained by using the member function asResource of CPointer. |
| CStringResource | Indicates the resource management type corresponding to CString. Instances of this type can be obtained by using the member function asResource of CString. |
| DefaultHasher | Provides the default hash algorithm implementation. |
| Duration | Indicates an interval of the time type, which provides common static instances and the calculation and comparison functionalities. |
| LibC | Provides C APIs that are frequently used in Cangjie, such as APIs for applying for and releasing CType instances on the heap. |
| Range<T> where T <: Countable<T> & Comparable<T> & Equatable<T> | Indicates an interval type used to indicate a sequence of T with a fixed range and step. T must be countable and ordered. |
| String | Indicates a Cangjie string with a series of string operations provided, such as construction, search, and concatenation. |
Exception Class
| Name | Description |
|---|---|
| ArithmeticException | Indicates the arithmetic exception class which is thrown when an arithmetic exception occurs. |
| Error | Specifies the parent class of all error classes. This class cannot be inherited or initialized, but can be captured. |
| Exception | Specifies the parent class of all exception classes. |
| IllegalArgumentException | Indicates the exception class that is thrown when a parameter is invalid. |
| IllegalFormatException | Indicates the exception class that is thrown when the format of a variable is invalid or not standard. |
| IllegalMemoryException | Indicates the exception class that is thrown when a memory operation error occurs. |
| IllegalStateException | Indicates the exception class that is thrown when a status is invalid. |
| IncompatiblePackageException | Indicates the exception class that is thrown when the package is incompatible. |
| IndexOutOfBoundsException | Indicates the exception class that is thrown when an index is out of range. |
| InternalError | Indicates the internal error class. This class cannot be initialized but can be captured. |
| NegativeArraySizeException | Indicates the exception class that is thrown when the array size is negative. |
| NoneValueException | Indicates the exception class that is thrown (usually in the getOrThrow function) when the value of the Option<T> instance is None. |
| OutOfMemoryError | Indicates the out-of-memory error class. This class cannot be inherited or initialized, but can be captured. |
| OverflowException | Indicates the exception class this is thrown when overflow occurs in an arithmetic operation. |
| SpawnException | Indicates the thread exception class, indicating that an exception occurs during thread processing. |
| StackOverflowError | Indicates the stack overflow error class. This class cannot be inherited or initialized, but can be captured. |
| TimeoutException | Indicates an exception that is thrown when the blocking operation times out. |
| UnsupportedException | Indicates the exception class that is thrown when a functionality is not supported. |