Packages

builtin
cbindgen
core
core.alloc
core.alloc.arena
core.alloc.atomic
core.alloc.fixed
core.alloc.gc
core.alloc.heap
core.alloc.log
core.alloc.memdebug
core.alloc.pool
core.alloc.ring
core.arg_parse
core.array
core.avl_tree
core.bucket_array
core.conv
core.doc
core.encoding
core.encoding.base64
core.encoding.csv
core.encoding.hex
core.encoding.json
core.encoding.kdl
core.encoding.osad
core.encoding.utf8
core.hash
core.hash.md5
core.hash.sha1
core.hash.sha256
core.heap
core.intrinsics
core.intrinsics.atomics
core.intrinsics.onyx
core.intrinsics.types
core.intrinsics.wasm
core.io
core.io.binary
core.iter
core.js
core.list
core.map
core.math
core.memory
core.misc
core.net
core.os
core.random
core.set
core.slice
core.string
core.sync
core.test
core.thread
core.time
main
runtime
runtime.info
runtime.platform
runtime.vars
simd

package core.conv

Custom_Format
Custom_Format :: struct {
    format: (&Format_Output, &Format, rawptr) -> void;
}

Tag-type used to specify how to format a structure.

@conv.Custom_Format.{ format_structure }
TheStructure :: struct { ... }
Custom_Format_Proc
Custom_Format_Proc :: struct {
    type: type_expr;
}

Tag-type used to specify that a certain procedure should be used to format a type.

@conv.Custom_Format_Proc.{ TheStructure }
format_structure :: (output: &conv.Format_Output, format: &conv.Format, data: &TheStructure) { ... }
Custom_Parse
Custom_Parse :: struct {
    parse: (rawptr, [] u8, Allocator) -> bool;
}

Tag-type used to specify how to parse a structure.

@conv.Custom_Parse.{ parse_structure }
TheStructure :: struct { ... }
Custom_Parse_Proc
Custom_Parse_Proc :: struct {
    type: type_expr;
}

Tag-type used to specify that a certain procedure should be used to parse a type.

@conv.Custom_Parse_Proc.{ TheStructure }
parse_structure :: (data: &TheStructure, input: str, allocator: Allocator) -> bool { ... }
Format
Format :: struct {
    pretty_printing: bool;
    quote_strings: bool;
    single_quote_strings: bool;
    dereference: bool;
    custom_format: bool;
    interpret_numbers: bool;
    digits_after_decimal: u32;
    indentation: u32;
    base: u64;
    minimum_width: u32;
}

Formatting options passed to a custom formatter.

Format_Flush_Callback
Format_Flush_Callback :: struct {
    data: rawptr;
    func: (rawptr, [] u8) -> bool;
}
Format_Output
Format_Output :: struct {
    data: [&] u8;
    count: u32;
    capacity: u32;
    flush: Format_Flush_Callback;
}

Passed to any custom formatter. Wraps outputting data to any source, using a flush callback function. Use write to output a string. When the internal buffer is filled, flush is called to empty the buffer to the final destination.

Methods
Format_Output.write
Format_Output.write :: (output: &Format_Output, c: u8) -> void
Format_Output.write :: (output: &Format_Output, s: [] u8) -> void
f64_to_str
f64_to_str :: (f: f64, buf: [] u8, digits_after_decimal: i32) -> [] u8

Converts a floating point number into a string, using the buffer provided.

This is better than what used to be, but still relies on converting the integer part of the float to an integer, which could overflow.

flush_to_dyn_str
flush_to_dyn_str :: (dynstr: &[..] u8, to_write: [] u8) -> bool
format
format :: (buffer: [] u8, format: [] u8, va: ..any) -> [] u8
format :: (output: &Format_Output, format: [] u8, va: ..any) -> [] u8
format :: (format: [] u8, va: ..any) -> [] u8
format :: (buffer: &[..] u8, format: [] u8, va: ..any) -> [] u8

Formats a string using the provided arguments and format specified string. This has many overloads to make it easy to work with.

format_any
format_any :: (output: &Format_Output, formatting: &Format, v: any) -> void

This procedure converts any value into a string, using the type information system. If a custom formatter is specified for the type, that is used instead. This procedure is generally not used directly; instead, through format or format_va.

format_va
format_va :: (buffer: [] u8, format: [] u8, va: [] any, flush: Format_Flush_Callback) -> [] u8
format_va :: (format: [] u8, va: [] any, allocator: Allocator) -> [] u8
format_va :: (buffer: &[..] u8, format: [] u8, va: [] any) -> [] u8
format_va :: (output: &Format_Output, format: [] u8, va: [] any) -> [] u8

Like format, but takes the arguments as an array of anys, not a variadic argument array.

i64_to_str
i64_to_str :: (n: i64, base: u64, buf: [] u8, min_length: i32, prefix: bool) -> [] u8

Converts an integer into a string using the buffer provided. Supports upto base 64. If prefix is true, binary numbers are prefixed with '0b' and hexadecimal numbers are prefixed with '0x'.

parse
parse :: ($T: type_expr, to_parse: str) -> ? T

Shortcut to parse a type T using parse_any.

parse_any
parse_any :: macro (v: &$T, to_parse: str, string_allocator) -> bool
parse_any :: (target: rawptr, data_type: type_expr, to_parse: [] u8, string_allocator: Allocator) -> bool

Parses many different types from a string into a value. Uses a custom parser if one has been specified for the type given.

parse_with_allocator
parse_with_allocator :: ($T: type_expr, to_parse: str, allocator: Allocator) -> ? T

Shortcut to parse a type T using parse_any, and specify an allocator.

register_custom_formatter
register_custom_formatter :: (formatter: (&Format_Output, &Format, &$T) -> void) -> void

Registers a formatting function for a particular type. This type is inferred from the type of the third argument in the given function.

register_custom_parser
register_custom_parser :: (parser: (&$T, str, Allocator) -> bool) -> void

Registers a parsing function for a particular type. This type is inferred from the type of the first argument in the given function.

str_to_f64
str_to_f64 :: macro (s: [] u8) -> f64
str_to_f64 :: (s: &[] u8) -> f64

Converts a string to a floating point number.

str_to_i64
str_to_i64 :: macro (s: [] u8, base: u32) -> i64
str_to_i64 :: (s: &[] u8, base: u32) -> i64

Converts a string into an integer. Works with positive and negative integers. If given a pointer to a string, will modify the string to extract the integer part.

u64_to_str
u64_to_str :: (n: u64, base: u64, buf: [] u8, min_length: i32, prefix: bool) -> [] u8

Converts an unsigned number into a string using the buffer provided. Behaves like i64_to_str.