Return to index

conversion functions

big_float = as_bigf(expr)

top

Convert expr to a float. Also ensures this is a copy.


big_int = as_bigi(expr)

top

Convert expr to a big integer. Also ensures this is a copy.


bool = as_bool(string)

top

Convert string to a boolean value, or errors


float = as_float(var)

top

Convert var to a float. Returns NaN on error.


integer = as_int(var)

top

Convert var to an integer, or errors.


integer = as_int64(var)

top

Convert var to an int64 type, or errors.


string = as_string(value[,precision])

top

Converts value to a string.


unsigned_integer = as_uint(var)

top

Convert var to a uint type, or errors.


int = asc(string)

top

Return a numeric representation of the first char in string.

Example:

# Example for asc
println asc("A")  # 65


string = base64d(string)

top

Return a string of the base64 decoding of string

Example:

println base64d("VGhlIEJhbnlhbiBUcmVl")
`
produces:
The Banyan Tree
`


string = base64e(string)

top

Return a string of the base64 encoding of string

Example:

println base64e("The Banyan Tree")
`
produces:
VGhlIEJhbnlhbiBUcmVl
`


int = btoi(bool)

top

Return an int which is either 1 when bool is true or else 0 when bool is false.

Example:

# Example for btoi
println btoi(true)  # 1


byte = byte(var)

top

Convert to a uint8 sized integer, or errors.


string = char(int)

top

Return a string representation of ASCII char int. Representations above 127 are empty.


string = dtoo(int)

top

Convert decimal int to octal string.

Example:

# Example for dtoo
println dtoo(8)  # 10


nil_or_any = f2n(any)

top

Converts false to nil or returns true.


bool = is_number(expression)

top

Returns true if expression can evaluate to a numeric value.

Example:

# Example for is_number
println is_number("123")  # true


bool = itob(int)

top

Return a boolean which is set to true when int is non-zero.

Example:

# Example for itob
println itob(1)  # true


[]any = json_decode(string)

top

Return a mixed type array representing a JSON string.

Example:

# Example for json_decode
println json_decode("[1,2,3]")  # [1,2,3]


string = json_format(string)

top

Return a formatted JSON representation of string, or an empty string on error.

Example:

# Example for json_format
json='{"a":1,"b":2}'
println json_format(json)


string = json_query(input_string,query_string[,map_bool])

top

Returns the result of processing input_string using the gojq library.

[#SOL]query_string is a jq-like query to operate with. If map_bool is false (default)

[#SOL]then a string is returned, otherwise an iterable list is returned.

Example:

# Example for json_query
var data='{"a":[1,2,3]}'
println json_query(data,".a")  # [1,2,3]


struct = m2s(map,struct_example)

top

Convert a map to struct following field form of struct_example.


uint64 = maxuint(var)

top

Represents the maximum possible uint value.


ansi_code_string = md2ansi(markdown_string)

top

Converts simple markdown syntax to Za ANSI colour codes.


int = otod(string)

top

Convert octal string to decimal int.

Example:

# Example for otod
println otod("77")  # 63


string = pp(map|slice, [max_depth], [indent_string])

top

Pretty print a map or slice with optional indentation, depth limit, and colour-coded section headings.


bool_success = read_struct(filename,name_of_destination_struct)

top

Read a struct from a file.

Example:

# Example for read_struct
println read_struct("/tmp/struct","s")


map = s2m(struct)

top

Convert a struct to map.


string or [][]any = table(data, [options])

top

Convert a slice of maps/structs to a text table, or parse a string to structured data.

[#SOL]Example options: .parse_only false (return [][]any), .has_headers false, .detect_sep true, .separator ",",

[#SOL].hide ["field1"], .show_only_ordered true, .colours map(.header "[#code1]", .data "[#code2]"),

[#SOL].table_width 80, .column_widths map(.name 10), .align map(.name "left"), .include_headers true,`

[#SOL].border_style "ascii", .truncate false, .column_order ["col1", "col2"])


typed_value = to_typed(value,type_string)

top

Convert value to the specified type type_string. Supports multi-dimensional arrays like '[][]int', '[][][]string', '[5][3]int', etc.


size = write_struct(filename,name_of_struct)

top

Sends a struct to file. Returns byte size written.

Example:

# Example for write_struct
var x={a:1,b:2}
println write_struct("/tmp/struct","x")  # bytes written