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.itemName
    

    fullPackageName 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.

NameDescription
coreSpecifies the core package of the standard library and provides fundamental APIs for Cangjie programming.
argoptProvides capabilities for parsing parameter names and values from command line parameter strings.
astContains the syntax parser of Cangjie source code and Cangjie syntax tree nodes, and provides syntactic parsing functions.
binaryProvides interfaces for converting and reversing the endianness of basic data types and binary byte arrays.
collectionProvides efficient implementations of commonly used data structures, definitions of related abstract interfaces, and functions in the collection type.
collection.concurrentProvides implementations of the concurrent collection type.
consoleProvides methods for interaction with standard input, standard output, and standard errors.
convertProvides 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.cipherProvides common APIs for symmetric encryption and decryption.
crypto.digestProvides common interfaces for digest algorithms, including MD5, SHA1, SHA224, SHA256, SHA384, SHA512, HMAC, and SM3.
database.sqlProvides interfaces for access to Cangjie databases.
derivingProvides a set of macros to automatically generate interface implementations.
envProvides information and functionalities related to the current process, including environment variables, command line arguments, standard streams, and exit programs.
fsProvides functions for operations with files, folders, paths, and file metadata.
ioAllows the program to exchange data with external devices.
mathProvides functionality including commonly used mathematical operations, constant definition, and floating-point number processing.
math.numericExtends the expressible range of basic types.
netProvides common network communication functionalities.
objectpoolProvides functionality of object caching and reuse.
overflowProvides overflow processing capabilities.
posixAdapts to POSIX system APIs.
processProvides process operation APIs, including process creation, standard flow obtaining, process waiting, and process information querying.
randomProvides the capability of generating pseudo-random numbers.
reflectProvides the reflection function, enabling a running program to obtain the type information of instances and execute read, write, and call operations.
regexProvides 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.
runtimeInteracts 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.
sortProvides sorting functions of the array type.
syncProvides concurrent programming capabilities.
timeProvides time-related types, including date and time, time interval, monotonic time, and time zone, and provides functionality of calculation and comparison.
unicodeProvides the capability of processing characters according to the unicode encoding standard.
unittestCompiles the unit test code of Cangjie projects and provides basic functionality such as code compilation, running, and debugging.
unittest.mockProvides 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.testmacroProvides macros for the unit test framework.
unittest.mock.mockmacroProvides macros for the mock framework.
unittest.commonProvides the unit test framework with the types and common methods required by printing.
unittest.diffProvides the unit test framework with APIs for printing difference comparison information.
unittest.prop_testProvides the unit test framework with the types and common methods required by parameterized tests.