std Module

Note:

The STD module cannot be directly imported through the import std command. Otherwise, an error indicating that the STD package cannot be found is reported during compilation. (error: can not find package 'std'). You are advised to import the std subpackage to use the std module.

Function Description

The std module refers to a standard library. In programming languages, a standard library is a group of predefined functions, classes, and structs. It is intended to provide commonly used functionality and tools so that developers can compile programs more quickly and efficiently.

Capabilities provided by the Cangjie standard library include but are not limited to the following:

  • I/O: console I/O and file I/O;
  • data structures: arrays, linked lists, and hash tables;
  • algorithms: sorting, summation, exponentiation, and logarithm;
  • date and time: obtaining time, formatting time, and setting scheduled tasks; and
  • concurrent programming: locks, atomic operations, and the like.

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.

Packages of the std Module

The std module provides the following packages:

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 a series of Convert functions for converting strings into specific types.
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.
ffi.pythonProvides the interoperability between Cangjie and Python for compatibility with powerful computing and AI ecosystems.
formatProvides the formatting capability for converting Cangjie instances into formatted strings.
fsProvides functions for operations with files, folders, paths, and file metadata.
ioAllows the program to exchange data with external devices.
logProvides functionality of log management and printing.
mathProvides functionality including commonly used mathematical operations, constant definition, and floating-point number processing.
math.numericExtends the expressible range of basic types.
objectpoolProvides functionality of object caching and reuse.
osProvides capabilities of obtaining information related to current process of the OR operation (such as process parameters, environment variables, and directory information), registering callback functions, and exiting the current process.
os.posixAdapts to POSIX interfaces.
os.processProvides Process operation interfaces, including process creation, standard flow obtaining, process waiting, and process information querying.
overflowProvides overflow processing capabilities.
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 (ASCII character strings only) through regular expressions, and supports functions 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.
socketProvides functionality such as starting a Socket server, connecting to a Socket server, sending data, and receiving data, and is used for network communication.
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.