EgretDoc
Back to Home
Location:system/encoding

Module

Module documentation.

moduleencoding
@briefEncoding utilities
@detailsProvides Base64 encode/decode and JSON/XML/KV serialization for Map<String,String>.
@see
  • index.html

Classes

Classes and inheritance.

Functions

Free functions and class methods.

functionencoding::__byte_at
Signatureextern func __byte_at(s: String, idx: Int) -> Int;
extern func __byte_at(s: String, idx: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__char_from_code`.
@briefBinds the low-level runtime symbol `__byte_at`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
  • sInput string.
  • idxZero-based index.
@returnReturns the operation result as `Int`.
functionencoding::__char_from_code
Signatureextern func __char_from_code(code: Int) -> String;
extern func __char_from_code(code: Int) -> String;

/*
@briefBinds the low-level runtime symbol `__char_from_code`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
  • codeNumeric status, error, signal, opcode, or platform code handled by this API.
@returnReturns the operation result as `String`.
functionencoding::byte_at
Signaturefunc byte_at(s: String, idx: Int) -> Int
func byte_at(s: String, idx: Int) -> Int {
    return __byte_at(s, idx);
}
@briefProvides the system library operation `byte_at`.
@detailsExecutes the `byte_at` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • sInput string.
  • idxZero-based index.
@returnReturns the operation result as `Int`.
functionencoding::byte_from_code
Signaturefunc byte_from_code(code: Int) -> String
func byte_from_code(code: Int) -> String {
    return __char_from_code(code);
}
@briefProvides the system library operation `byte_from_code`.
@detailsExecutes the `byte_from_code` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
  • codeNumeric status, error, signal, opcode, or platform code handled by this API.
@returnReturns the operation result as `String`.
functionencoding::encode_to_string
Signaturefunc encode_to_string(s: String) -> String
func encode_to_string(s: String) -> String {
    let alphabet: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    let n: Int = std.len(s);
@briefBase64 encoding
@param
  • sInput data (processed as bytes)
@returnBase64-encoded string
@noteBytes are read via __byte_at.
functionencoding::decode_string
Signaturefunc decode_string(b64: String) -> String
func decode_string(b64: String) -> String {
    let alphabet: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    let n: Int = std.len(b64);
@briefBase64 decoding
@param
  • b64Base64 string
@returnDecoded data (bytes concatenated into a String)
@noteThis function does not return errors.
functionencoding::is_ws
Signaturefunc is_ws(c: Int) -> Bool
func is_ws(c: Int) -> Bool {
    if c == 32 || c == 9 || c == 10 || c == 13 {
        return true;
@briefCheck JSON whitespace
@detailsInternal helper: recognizes space / tab / LF / CR.
@param
  • cByte code (ASCII)
@returnWhether it is a whitespace character
@noteInternal helper
functionencoding::skip_ws
Signaturefunc skip_ws(s: String, i: Int) -> Int
func skip_ws(s: String, i: Int) -> Int {
    let done: Bool = false;
    loop (; !done; ) {
@briefSkip whitespace
@detailsInternal helper: skips consecutive whitespace starting from i and returns the new position.
@param
  • sInput string
  • iStart index
@returnIndex after skipping whitespace (may equal len(s))
@noteInternal helper
functionencoding::parse_string
Signaturefunc parse_string(s: String, i: Int) -> String
func parse_string(s: String, i: Int) -> String {
    let out: String = "";
    i += 1;
@briefParse a JSON string literal
@param
  • sInput JSON text
  • iIndex of the starting quote
@returnParsed string content (without quotes)
@noteInternal helper
functionencoding::parse_string_end
Signaturefunc parse_string_end(s: String, i: Int) -> Int
func parse_string_end(s: String, i: Int) -> Int {
    i += 1;
    let done: Bool = false;
@briefFind end of a JSON string literal
@param
  • sInput JSON text
  • iIndex of the starting quote
@returnIndex after the closing quote (for continued parsing)
@noteInternal helper
functionencoding::escape_string
Signaturefunc escape_string(s: String) -> String
func escape_string(s: String) -> String {
    let out: String = "";
    loop (let i: Int = 0; i < std.len(s); i += 1) {
@briefEscape a JSON string
@param
  • sRaw string
@returnEscaped string (without surrounding quotes)
@noteInternal helper
functionencoding::unmarshal_str_str
Signaturefunc unmarshal_str_str(json: String) -> collections.Map<String, String>
func unmarshal_str_str(json: String) -> collections.Map<String, String> {
    let m: collections.Map<String, String> = new collections.Map<String, String>();
    let i: Int = skip_ws(json, 0);
@briefParse JSON into Map<String,String>
@param
  • jsonJSON text
@returnParsed key/value map
@warningThis is a lightweight parser and is not fully JSON-standard compliant.
functionencoding::marshal_str_str
Signaturefunc marshal_str_str(m: collections.Map<String, String>) -> String
func marshal_str_str(m: collections.Map<String, String>) -> String {
    let keys: collections.Vector<String> = m.keys();
    let out: String = "{";
@briefSerialize Map<String,String> as JSON
@param
  • mKey/value map
@returnJSON text
@noteKey order depends on the order returned by Map<String,String>.keys().
functionencoding::replace_all
Signaturefunc replace_all(s: String, pat: String, rep: String) -> String
func replace_all(s: String, pat: String, rep: String) -> String {
    let out: String = "";
    let i: Int = 0;
@briefReplace all occurrences
@detailsInternal helper: replaces all occurrences of pat in s with rep.
@param
  • sInput string
  • patSubstring to find
  • repReplacement substring
@returnReplaced string
@noteInternal helper
functionencoding::escape
Signaturefunc escape(s: String) -> String
func escape(s: String) -> String {
    let out: String = s;
    out = replace_all(out, "&", "&amp;");
@briefXML entity escaping
@param
  • sInput string
@returnEscaped string
@see
  • Unescape
functionencoding::unescape
Signaturefunc unescape(s: String) -> String
func unescape(s: String) -> String {
    let out: String = s;
    out = replace_all(out, "&apos;", "'");
@briefXML entity unescaping
@detailsConverts XML entities produced by Escape back to their original characters.
@param
  • sInput string
@returnUnescaped string
@see
  • Escape
functionencoding::marshal_map_str_str
Signaturefunc marshal_map_str_str(m: collections.Map<String, String>) -> String
func marshal_map_str_str(m: collections.Map<String, String>) -> String {
    let keys: collections.Vector<String> = m.keys();
    let out: String = "<root>";
@briefSerialize Map<String,String> to simple XML
@param
  • mKey/value map
@returnXML text
@noteKey order depends on the order returned by Map<String,String>.keys().
@warningDoes not support attributes, nesting, namespaces, or other XML features.
functionencoding::unmarshal_map_str_str
Signaturefunc unmarshal_map_str_str(xml: String) -> collections.Map<String, String>
func unmarshal_map_str_str(xml: String) -> collections.Map<String, String> {
    let m: collections.Map<String, String> = new collections.Map<String, String>();
    let s: String = xml;
@briefParse simple XML into Map<String,String>
@param
  • xmlXML text
@returnParsed key/value map
@warningThis is a lightweight parser and is not fully XML-standard compliant.
functionencoding::escape_gob
Signaturefunc escape_gob(s: String) -> String
func escape_gob(s: String) -> String {
    let out: String = "";
    loop (let i: Int = 0; i < std.len(s); i += 1) {
@briefKV-line escaping
@param
  • sRaw string
@returnEscaped string
@noteInternal helper
functionencoding::unescape_gob
Signaturefunc unescape_gob(s: String) -> String
func unescape_gob(s: String) -> String {
    let out: String = "";
    let i: Int = 0;
@briefKV-line unescaping
@param
  • sEscaped string
@returnUnescaped string
@noteInternal helper
functionencoding::encode_map_str_str
Signaturefunc encode_map_str_str(m: collections.Map<String, String>) -> String
func encode_map_str_str(m: collections.Map<String, String>) -> String {
    let keys: collections.Vector<String> = m.keys();
    let out: String = "";
@briefEncode Map<String,String> as KV-line format
@param
  • mKey/value map
@returnEncoded text
@noteKey order depends on the order returned by Map<String,String>.keys().
@see
  • DecodeMapStrStr
functionencoding::decode_map_str_str
Signaturefunc decode_map_str_str(data: String) -> collections.Map<String, String>
func decode_map_str_str(data: String) -> collections.Map<String, String> {
    let m: collections.Map<String, String> = new collections.Map<String, String>();
    let i: Int = 0;
@briefDecode KV-line format into Map<String,String>
@param
  • dataInput text
@returnParsed key/value map
@see
  • EncodeMapStrStr

Variables

Class fields (var).