std Module
The Cangjie standard library (std) is included by default when the Cangjie SDK is installed. The standard library predefines a group of functions, classes, and structures, providing common functionalities and tools so that developers can compile programs more quickly and efficiently.
The Cangjie standard library has three features:
- Ease of use: The standard library is released with the compiler and tool chain. You do not need to download them separately.
- Function universality: The standard library provides some commonly-used library capabilities so that you can solve most basic problems.
- Quality benchmark: The standard library aims to set examples and benchmarks for other Cangjie libraries in terms of performance and code style.
Usage
In the Cangjie programming language, the standard library includes several packages. A package is the minimum unit of compilation. Each package can output products such as abstract syntax tree (AST) files, static library files, and dynamic library files. A package can define subpackages to form a tree structure. A package without a parent package is called a root package. The entire tree consisting of the root package and its subpackages (including their respective subpackages) is called a module. The name of a module is the same as that of the root package. A module is the minimum unit released by a developer.
The rules for importing packages are as follows:
-
A top-level declaration or definition in a package can be imported. The syntax is as follows:
import fullPackageName.itemNamefullPackageName indicates the package name with the full path, and itemName indicates the declared name. For example:
import std.collection.ArrayList -
If more than one itemName to be imported belong to the same fullPackageName, use the following statement:
import fullPackageName.{itemName[, itemName]*}For example:
import std.collection.{ArrayList, HashMap} -
All public-qualified top-level declarations or definitions in the fullPackageName package can also be imported. The syntax is as follows:
import fullPackageName.*For example:
import std.collection.*
Packages
The std module contains several packages, which provide rich basic functionalities.
| Name | Description |
|---|---|
| core | Specifies the core package of the standard library and provides fundamental APIs for Cangjie programming. |
| argopt | Provides capabilities for parsing parameter names and values from command line parameter strings. |
| ast | Contains the syntax parser of Cangjie source code and Cangjie syntax tree nodes, and provides syntactic parsing functions. |
| binary | Provides interfaces for converting and reversing the endianness of basic data types and binary byte arrays. |
| collection | Provides efficient implementations of commonly used data structures, definitions of related abstract interfaces, and functions in the collection type. |
| collection.concurrent | Provides implementations of the concurrent collection type. |
| console | Provides methods for interaction with standard input, standard output, and standard errors. |
| convert | Provides the Convert series functions for converting strings to specific types and provides the formatting capability. It is mainly used to convert Cangjie instances to formatted strings. |
| crypto.cipher | Provides common APIs for symmetric encryption and decryption. |
| crypto.digest | Provides common interfaces for digest algorithms, including MD5, SHA1, SHA224, SHA256, SHA384, SHA512, HMAC, and SM3. |
| database.sql | Provides interfaces for access to Cangjie databases. |
| deriving | Provides a set of macros to automatically generate interface implementations. |
| env | Provides information and functionalities related to the current process, including environment variables, command line arguments, standard streams, and exit programs. |
| fs | Provides functions for operations with files, folders, paths, and file metadata. |
| io | Allows the program to exchange data with external devices. |
| math | Provides functionality including commonly used mathematical operations, constant definition, and floating-point number processing. |
| math.numeric | Extends the expressible range of basic types. |
| net | Provides common network communication functionalities. |
| objectpool | Provides functionality of object caching and reuse. |
| overflow | Provides overflow processing capabilities. |
| posix | Adapts to POSIX system APIs. |
| process | Provides process operation APIs, including process creation, standard flow obtaining, process waiting, and process information querying. |
| random | Provides the capability of generating pseudo-random numbers. |
| reflect | Provides the reflection function, enabling a running program to obtain the type information of instances and execute read, write, and call operations. |
| regex | Provides the capability of analyzing and processing text (Unicode strings that support UTF-8 encoding) through regular expressions, and supports the functionalities such as search, segmentation, replacement, and verification. |
| runtime | Interacts with the runtime environment of a program. It provides a series of functions and variables for controlling, managing, and monitoring the execution of the program. |
| sort | Provides sorting functions of the array type. |
| sync | Provides concurrent programming capabilities. |
| time | Provides time-related types, including date and time, time interval, monotonic time, and time zone, and provides functionality of calculation and comparison. |
| unicode | Provides the capability of processing characters according to the unicode encoding standard. |
| unittest | Compiles the unit test code of Cangjie projects and provides basic functionality such as code compilation, running, and debugging. |
| unittest.mock | Provides a mock framework for Cangjie unit tests and provides APIs for creating and configuring mock objects. These mock objects and the real objects have the same APIs. |
| unittest.testmacro | Provides macros for the unit test framework. |
| unittest.mock.mockmacro | Provides macros for the mock framework. |
| unittest.common | Provides the unit test framework with the types and common methods required by printing. |
| unittest.diff | Provides the unit test framework with APIs for printing difference comparison information. |
| unittest.prop_test | Provides the unit test framework with the types and common methods required by parameterized tests. |