package core.conv
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 :: 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 :: 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 :: 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 :: struct {
pretty_printing: bool
quote_strings: bool
single_quote_strings: bool
dereference: bool
custom_format: bool
interpret_numbers: bool
unpack_any: bool
digits_after_decimal: u32
indentation: u32
base: u64
minimum_width: u32
}
Formatting options passed to a custom formatter.
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.
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.
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 :: (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 :: (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 any
s, not a variadic argument array.
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_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 :: ($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 :: (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 :: (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 :: macro (s: [] u8) -> f64
str_to_f64 :: (s: &[] u8) -> f64
Converts a string to a floating point number.
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.