package core:strconv

⌘K
Ctrl+K
or
/

    Overview

    Conversions to and from string representations of other data types like integers and booleans.

    Packages 1

    decimalMultiple precision decimal numbers for use by the strconv package.

    Index

    Variables (2)
    Procedures (69)
    `#config` values (1)

    Types

    Decimal_Slice ¶

    Decimal_Slice :: struct {
    	digits:        []u8,
    	count:         int,
    	decimal_point: int,
    	neg:           bool,
    }

    Float_Flag ¶

    Float_Flag :: enum int {
    	Plus, 
    }

    Float_Flags ¶

    Float_Flags :: bit_set[Float_Flag]

    Related Procedures With Parameters

    Float_Info ¶

    Float_Info :: struct {
    	mantbits: uint,
    	expbits:  uint,
    	bias:     int,
    }

    Related Procedures With Parameters

    Int_Flag ¶

    Int_Flag :: enum int {
    	// Prefixes the integer depending on the base:
    	// - `0b`: base 2
    	// - `0o`: base 8
    	// - `0z`: base 12
    	// - `0x`: base 16
    	// 
    	// NOTE: A base 10 integer receives no prefix, even if this flag is specified.
    	Prefix, 
    	// Prepend a `+` sign before positive integers.
    	Plus, 
    }

    Int_Flags ¶

    Int_Flags :: bit_set[Int_Flag]

    Related Procedures With Parameters

    Rune_Escaping_Option ¶

    Rune_Escaping_Option :: enum int {
    	// When set, runes will be escaped such that their encoded byte representation
    	// only contains ASCII characters.
    	ascii_compatible, 
    	// When set, the runes `<`, `>` and `&` will be escaped as `\x3c`, `\x3e` and `\x26` respectively,
    	// making them suitable for text content nodes in HTML (and XML) documents.
    	// 
    	// **NOTE:** This does NOT encode them as HTML entities `<`, `>` or `&`.
    	html_safe, 
    }

    Rune_Escaping_Options ¶

    Rune_Escaping_Options :: bit_set[Rune_Escaping_Option]
     

    Lets callers configure how individual runes are escaped when using:

    Related Procedures With Parameters

    Constants

    ESCAPED_RUNE_MAX_NEEDED_BYTES ¶

    ESCAPED_RUNE_MAX_NEEDED_BYTES :: 10
     

    Maximum number of free buffer bytes needed by encode_and_escape_rune in the worst case, which is \U########.

    FAST_FLOAT ¶

    FAST_FLOAT :: #config(STRCONV_FAST_FLOAT, true)
    -define:STRCONV_FAST_FLOAT=true
     

    Disable with -define:STRCONV_FAST_FLOAT=false to drop the Eisel-Lemire step, the fast float formatting and their table, and to read digits one at a time (instead of eight). Float formatting then uses only the decimal path.

    QUOTED_RUNE_MAX_NEEDED_BYTES ¶

    QUOTED_RUNE_MAX_NEEDED_BYTES :: ESCAPED_RUNE_MAX_NEEDED_BYTES + 2
     

    Maximum number of free buffer bytes needed by quote_rune in the worst case.

    Variables

    hex_digit_table ¶

    @(rodata)
    hex_digit_table: [256]u8 = …
     

    NOTE(MatthiasH): direct lookup was always faster in benchmarks

    Procedures

    atof ¶

    Deprecated. Use strconv.parse_f64() instead
    @(deprecated="Use strconv.parse_f64() instead")
    atof :: proc(s: string) -> f64 {…}

    atoi ¶

    Deprecated. Use strconv.parse_int() instead
    @(deprecated="Use strconv.parse_int() instead")
    atoi :: proc(s: string) -> int {…}

    decimal_to_float_bits ¶

    decimal_to_float_bits :: proc(
    	d:    ^strconv_decimal.Decimal, 
    	info: ^Float_Info, 
    ) -> (b: u64, overflow: bool) {…}
     

    Converts a decimal number to its floating-point representation with the given format and returns the resulting bits

    Inputs

    • d: Pointer to the decimal number to convert
    • info: Pointer to the Float_Info structure containing information about the floating-point format

    Returns

    • b: The bits representing the floating-point number
    • overflow: A boolean indicating whether an overflow occurred during conversion

    digit_to_int ¶

    digit_to_int :: proc(r: rune) -> (value: int, ok: bool) {…}
     

    Accepts '0'..='9', otherwise returns ok = false

    encode_and_escape_rune ¶

    encode_and_escape_rune :: proc(
    	buf:        []u8, 
    	r:          rune, 
    	quote_char: u8, 
    	options:    bit_set[Rune_Escaping_Option] = nil, 
    ) -> (result: string, ok: bool) #optional_ok {…}
     

    Encodes a single rune r as UTF-8, escaping it if appropriate, and palces the result into buf.

    Inputs

    • buf: The byte buffer into which the encoded and escaped rune will be written.
    • r: The rune which should be encoded.
    • quote_char: A character which this procedure will consider necessary to escape. Usually, this is ' if this is called to encode a single quoted rune (e.g. 'a'), or " if this is called to encode runes in a quoted string (e.g. "abc"). Specify quote_char = 0 to disable this feature.
    • options: Specify extended options.

    Returns

    • result: The encoded and escaped representation of the rune, if successful.
    • ok: true on success, false if buf was not large enough.

    Remarks

    This procedure escapes runes when it would have been appropriate to do so in an Odin string literal. Escaping also follows the rules and syntax of Odin in general.

    This includes, but may not be limited to, control characters, invisible characters, and characters which would likely cause display issues such as combining marks (see: unicode.is_printable).

    Invalid code points, including surrogate values, are encoded as the replacement character.

    fast_float_compute_float ¶

    fast_float_compute_float :: proc "contextless" ($T: typeid, q: int, w: u64) -> u64 {…}
     

    Computes the T closest to w * 10^q, rounding ties to even.

    w must be the exact decimal significand. When the input had more digits than fit in a u64, call this with both the truncated significand w and w + 1: if both calls return the same bits, the result is correct. Otherwise, use a slow path.

    Inputs

    • T: f32 or f64
    • q: The decimal exponent
    • w: The decimal significand

    Returns

    • The IEEE-754 bit pattern of the result, without the sign bit. An overflow gives the bit pattern of infinity.

    format_digits ¶

    format_digits :: proc(
    	buf:       []u8, 
    	shortest:  bool, 
    	neg:       bool, 
    	digs:      Decimal_Slice, 
    	precision: int, 
    	fmt:       u8, 
    	flags:     bit_set[Float_Flag], 
    ) -> []u8 {…}
     

    Converts a decimal floating-point number into a byte buffer with the given format

    Inputs

    • buf: The byte buffer to store the formatted number
    • shortest: If true, generates the shortest representation of the number
    • neg: If true, the number is negative
    • digs: The decimal number to be formatted
    • precision: The number of digits after the decimal point
    • fmt: The format specifier (accepted values: 'f', 'F', 'e', 'E', 'g', 'G')
    • flags: Additional formatting options

    Returns

    • A byte slice containing the formatted decimal floating-point number

    ftoa ¶

    Deprecated. Use strconv.write_float() instead
    @(deprecated="Use strconv.write_float() instead")
    ftoa :: proc(buf: []u8, f: f64, fmt: u8, prec, bit_size: int) -> string {…}

    generic_ftoa ¶

    generic_ftoa :: proc(
    	buf:                 []u8, 
    	val:                 f64, 
    	fmt:                 u8, 
    	precision, bit_size: int, 
    	flags:               bit_set[Float_Flag], 
    ) -> []u8 {…}
     

    Converts a floating-point number to a string with the specified format and precision.

    Inputs

    buf: A byte slice to store the resulting string val: The floating-point value to be converted fmt: The formatting byte, accepted values are 'e', 'E', 'f', 'F', 'g', 'G' precision: The number of decimal places to round to bit_size: The size of the floating-point number in bits, valid values are 16, 32, 64 flags: Additional formatting options; .Plus prefixes non-negative finite values with +

    Returns

    • A byte slice containing the formatted string

    Remarks

    Some callers assume that the written payload will always start at index 0 in buf. This means the implementation cannot trim anything from the beginning of the buffer after-the-fact.

    Example:
    buf: [32]byte
    val := 3.141592
    fmt := 'f'
    precision := 2
    bit_size := 64
    result := strconv.generic_ftoa(buf[:], val, fmt, precision, bit_size) -> "3.14"
    

    hex_float_bits ¶

    hex_float_bits :: proc "contextless" (
    	mantissa:   u64, 
    	exp:        int, 
    	neg, trunc: bool, 
    	info:       ^Float_Info, 
    ) -> (float_bits: u64, ok: bool) {…}
     

    Converts mantissa * 2^exp to the bits of the float type that info describes, rounded to nearest, ties to even. trunc means that the exact value is a little larger than mantissa * 2^exp (nonzero digits were dropped).

    Returns

    • float_bits: The bits of the float, with the sign.
    • ok: false if the value overflows. Then float_bits is infinity.

    is_eight_hex_digits ¶

    is_eight_hex_digits :: proc "contextless" (v: u64) -> bool {…}

    is_integer_negative ¶

    is_integer_negative :: proc(x: u64, is_signed: bool, bit_size: int) -> (u: u64, neg: bool) {…}
     

    Determines whether the given unsigned 64-bit integer is a negative value by interpreting it as a signed integer with the specified bit size.

    Inputs

    • x: The unsigned 64-bit integer to check for negativity
    • is_signed: A boolean indicating if the input should be treated as a signed integer
    • bit_size: The bit size of the signed integer representation (8, 16, 32, or 64)

    Returns

    • u: The absolute value of the input integer
    • neg: A boolean indicating whether the input integer is negative

    is_integer_negative_128 ¶

    is_integer_negative_128 :: proc(
    	x:         u128, 
    	is_signed: bool, 
    	bit_size:  int, 
    ) -> (u: u128, neg: bool) {…}
     

    Determines whether the given unsigned 128-bit integer is a negative value by interpreting it as a signed integer with the specified bit size.

    Inputs

    • x: The unsigned 128-bit integer to check for negativity
    • is_signed: A boolean indicating if the input should be treated as a signed integer
    • bit_size: The bit size of the signed integer representation (8, 16, 32, 64, or 128)

    Returns

    • u: The absolute value of the input integer
    • neg: A boolean indicating whether the input integer is negative

    is_made_of_eight_digits_fast ¶

    is_made_of_eight_digits_fast :: proc "contextless" (v: u64) -> bool {…}
     

    Reports if all 8 bytes of v are ASCII digits

    is_made_of_four_digits_fast ¶

    is_made_of_four_digits_fast :: proc "contextless" (v: u32) -> bool {…}

    itoa ¶

    Deprecated. Use strconv.write_int() instead
    @(deprecated="Use strconv.write_int() instead")
    itoa :: proc(buf: []u8, i: int) -> string {…}

    loop_parse_if_eight_digits ¶

    loop_parse_if_eight_digits :: proc "contextless" (s: string, i: int, m: u64) -> (int, u64) {…}
     

    Returns the new position and mantissa

    parse_bool ¶

    parse_bool :: proc(s: string, n: ^int = nil) -> (result: bool = false, ok: bool) {…}
     

    Parses a boolean value from the input string

    Inputs

    • s: The input string
      • true: "1", "t", "T", "true", "TRUE", "True"
      • false: "0", "f", "F", "false", "FALSE", "False"
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)

    Returns

    • result: The parsed boolean value (default: false)
    • ok: A boolean indicating whether the parsing was successful

    parse_complex128 ¶

    parse_complex128 :: proc(str: string, n: ^int = nil) -> (value: complex128, ok: bool) {…}
     

    Parses a 128-bit complex number from a string

    Inputs

    • str: The input string containing a 128-bit complex number.
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil).
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_complex128_example :: proc() {
    	n: int
    	c, ok := strconv.parse_complex128("3+1i", &n)
    	fmt.printfln("%v %i %t", c, n, ok)
    
    	c, ok = strconv.parse_complex128("5+7i hellope", &n)
    	fmt.printfln("%v %i %t", c, n, ok)
    }
    
    Output:
    3+1i 4 true
    5+7i 4 false
    

    Returns

    • value: The parsed 128-bit complex number.
    • ok: false if a complex number could not be found, or if the input string contained more than just the number.

    parse_complex32 ¶

    parse_complex32 :: proc(str: string, n: ^int = nil) -> (value: complex32, ok: bool) {…}
     

    Parses a 32-bit complex number from a string

    Inputs

    • str: The input string containing a 32-bit complex number.
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil).
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_complex32_example :: proc() {
    	n: int
    	c, ok := strconv.parse_complex32("3+1i", &n)
    	fmt.printfln("%v %i %t", c, n, ok)
    
    	c, ok = strconv.parse_complex32("5+7i hellope", &n)
    	fmt.printfln("%v %i %t", c, n, ok)
    }
    
    Output:
    3+1i 4 true
    5+7i 4 false
    

    Returns

    • value: The parsed 32-bit complex number.
    • ok: false if a complex number could not be found, or if the input string contained more than just the number.

    parse_complex64 ¶

    parse_complex64 :: proc(str: string, n: ^int = nil) -> (value: complex64, ok: bool) {…}
     

    Parses a 64-bit complex number from a string

    Inputs

    • str: The input string containing a 64-bit complex number.
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil).
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_complex64_example :: proc() {
    	n: int
    	c, ok := strconv.parse_complex64("3+1i", &n)
    	fmt.printfln("%v %i %t", c, n, ok)
    
    	c, ok = strconv.parse_complex64("5+7i hellope", &n)
    	fmt.printfln("%v %i %t", c, n, ok)
    }
    
    Output:
    3+1i 4 true
    5+7i 4 false
    

    Returns

    • value: The parsed 64-bit complex number.
    • ok: false if a complex number could not be found, or if the input string contained more than just the number.

    parse_digits_with_separators ¶

    @(cold)
    parse_digits_with_separators :: proc "contextless" (
    	s:        string, 
    	i:        int, 
    	mantissa: u64, 
    ) -> (int, u64, int) {…}
     

    Returns the new position, the mantissa and the number of digits

    parse_eight_digits_unrolled ¶

    parse_eight_digits_unrolled :: proc "contextless" (chars: u64) -> u64 {…}
     

    Converts 8 ASCII digits (the first digit in the lowest byte) to their value

    parse_eight_hex_digits ¶

    parse_eight_hex_digits :: proc "contextless" (v: u64) -> u64 {…}

    parse_exponent_with_separators ¶

    @(cold)
    parse_exponent_with_separators :: proc "contextless" (s: string, i: int, x: int) -> (int, int) {…}

    parse_f32 ¶

    parse_f32 :: proc(s: string, n: ^int = nil) -> (value: f32, ok: bool) {…}
     

    Parses a 32-bit floating point number from a string

    Inputs

    • s: The input string containing a 32-bit floating point number.
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil).
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_f32_example :: proc() {
    	n, ok := strconv.parse_f32("1234eee")
    	fmt.printfln("%.3f %v", n, ok)
    
    	n, ok = strconv.parse_f32("5678e2")
    	fmt.printfln("%.3f %v", n, ok)
    }
    
    Output:
    0.000 false
    567800.000 true
    

    Returns

    • value: The parsed 32-bit floating point number.
    • ok: false if a base 10 float could not be found, or if the input string contained more than just the number.

    parse_f32_prefix ¶

    parse_f32_prefix :: proc(str: string) -> (value: f32, nr: int, ok: bool) {…}
     

    Parses a 32-bit floating point number from a string and returns the parsed number, the length of the parsed substring, and a boolean indicating whether the parsing was successful

    Inputs

    • str: The input string containing a 32-bit floating point number.
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_f32_prefix_example :: proc() {
    	n, _, ok := strconv.parse_f32_prefix("1234eee")
    	fmt.printfln("%.3f %v", n, ok)
    
    	n, _, ok = strconv.parse_f32_prefix("5678e2")
    	fmt.printfln("%.3f %v", n, ok)
    }
    
    Output:
    0.000 false
    567800.000 true
    

    Returns

    • value: The parsed 32-bit floating point number.
    • nr: The length of the parsed substring.
    • ok: A boolean indicating whether the parsing was successful.

    parse_f64 ¶

    parse_f64 :: proc(str: string, n: ^int = nil) -> (value: f64, ok: bool) {…}
     

    Parses a 64-bit floating point number from a string

    Inputs

    • str: The input string containing a 64-bit floating point number.
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil).
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_f64_example :: proc() {
    	n, ok := strconv.parse_f64("1234eee")
    	fmt.printfln("%.3f %v", n, ok)
    
    	n, ok = strconv.parse_f64("5678e2")
    	fmt.printfln("%.3f %v", n, ok)
    }
    
    Output:
    0.000 false
    567800.000 true
    

    Returns

    • value: The parsed 64-bit floating point number.
    • ok: false if a base 10 float could not be found, or if the input string contained more than just the number.

    parse_f64_prefix ¶

    parse_f64_prefix :: proc(str: string) -> (value: f64, nr: int, ok: bool) {…}
     

    Parses a 64-bit floating point number from a string and returns the parsed number, the length of the parsed substring, and a boolean indicating whether the parsing was successful

    Inputs

    • str: The input string containing a 64-bit floating point number.
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_f64_prefix_example :: proc() {
    	n, _, ok := strconv.parse_f64_prefix("12.34eee")
    	fmt.printfln("%.3f %v", n, ok)
    
    	n, _, ok = strconv.parse_f64_prefix("12.34e2")
    	fmt.printfln("%.3f %v", n, ok)
    
    	n, _, ok = strconv.parse_f64_prefix("13.37 hellope")
    	fmt.printfln("%.3f %v", n, ok)
    }
    
    Output:
    0.000 false
    1234.000 true
    13.370 true
    

    Returns

    • value: The parsed 64-bit floating point number.
    • nr: The length of the parsed substring.
    • ok: false if a base 10 float could not be found

    parse_float_prefix_generic ¶

    parse_float_prefix_generic :: proc($T: typeid, str: string) -> (value: T, nr: int, ok: bool) {…}
     

    Parses directly to T, so the result is correctly rounded for both f32 and f64.

    parse_four_digits_unrolled ¶

    parse_four_digits_unrolled :: proc "contextless" (chars: u32) -> u64 {…}

    parse_i128_maybe_prefixed ¶

    parse_i128_maybe_prefixed :: proc(str: string, n: ^int = nil) -> (value: i128, ok: bool) {…}
     

    Parses an integer value from a string in base 10, unless there's a prefix

    Inputs

    • str: The input string containing the integer value
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_i128_maybe_prefixed_example :: proc() {
    	n, ok := strconv.parse_i128_maybe_prefixed("1234")
    	fmt.println(n, ok)
    
    	n, ok = strconv.parse_i128_maybe_prefixed("0xeeee")
    	fmt.println(n, ok)
    }
    
    Output:
    1234 true
    61166 true
    

    Returns

    • value: The parsed i128 value
    • ok: false if a valid integer could not be found, or if the input string contained more than just the number.

    parse_i128_of_base ¶

    parse_i128_of_base :: proc(str: string, base: int, n: ^int = nil) -> (value: i128, ok: bool) {…}
     

    Parses an integer value from a string in the given base, without any prefix

    Inputs

    • str: The input string containing the integer value
    • base: The base (radix) to use for parsing the integer (1-16)
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_i128_of_base_example :: proc() {
    	n, ok := strconv.parse_i128_of_base("-1234eeee", 10)
    	fmt.println(n,ok)
    }
    
    Output:
    -1234 false
    

    Returns

    • value: The parsed i128 value
    • ok: false if no numeric value of the appropriate base could be found, or if the input string contained more than just the number.

    parse_i64_maybe_prefixed ¶

    parse_i64_maybe_prefixed :: proc(str: string, n: ^int = nil) -> (value: i64, ok: bool) {…}
     

    Parses an integer value from the input string in base 10, unless there's a prefix

    Inputs

    • str: The input string to parse the integer value from
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_i64_maybe_prefixed_example :: proc() {
    	n, ok := strconv.parse_i64_maybe_prefixed("1234")
    	fmt.println(n,ok)
    
    	n, ok = strconv.parse_i64_maybe_prefixed("0xeeee")
    	fmt.println(n,ok)
    }
    
    Output:
    1234 true
    61166 true
    

    Returns

    • value: The parsed integer value
    • ok: ok=false if a valid integer could not be found, or if the input string contained more than just the number.

    parse_i64_of_base ¶

    parse_i64_of_base :: proc(str: string, base: int, n: ^int = nil) -> (value: i64, ok: bool) {…}
     

    Parses an integer value from the input string in the given base, without a prefix

    Inputs

    • str: The input string to parse the integer value from
    • base: The base of the integer value to be parsed (must be between 1 and 16)
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_i64_of_base_example :: proc() {
    	n, ok := strconv.parse_i64_of_base("-1234e3", 10)
    	fmt.println(n, ok)
    }
    
    Output:
    -1234 false
    

    Returns

    • value: Parses an integer value from a string, in the given base, without a prefix.
    • ok: ok=false if no numeric value of the appropriate base could be found, or if the input string contained more than just the number.

    parse_int ¶

    parse_int :: proc(s: string, base: int = 0, n: ^int = nil) -> (value: int, ok: bool) {…}
     

    Parses a signed integer value from the input string, using the specified base or inferring the base from a prefix

    Inputs

    • s: The input string to parse
    • base: The base of the number system to use for parsing (default: 0)
      • If base is 0, it will be inferred based on the prefix in the input string (e.g. '0x' for hexadecimal)
      • If base is not 0, it will be used for parsing regardless of any prefix in the input string
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_int_example :: proc() {
    	n, ok := strconv.parse_int("1234") // without prefix, inferred base 10
    	fmt.println(n,ok)
    
    	n, ok = strconv.parse_int("ffff", 16) // without prefix, explicit base
    	fmt.println(n,ok)
    
    	n, ok = strconv.parse_int("0xffff") // with prefix and inferred base
    	fmt.println(n,ok)
    }
    
    Output:
    1234 true
    65535 true
    65535 true
    

    Returns

    • value: The parsed int value
    • ok: false if no appropriate value could be found, or if the input string contained more than just the number.

    parse_number_string ¶

    parse_number_string :: proc "contextless" (s: string) -> (mantissa: u64, exp: int, neg, trunc: bool, nr: int, ok: bool) {…}
     

    Scans a decimal floating-point number at the start of s. A fast scanner for the decimal float syntax: [+-] digits [. digits] [(e|E) [+-] digits] It skips a _ between digits

    Returns

    • mantissa, exp: The value is mantissa * 10^exp. If trunc is true, the scanner dropped the significant digits after the first 19. Then the exact value is in the range [mantissa, mantissa + 1) * 10^exp.
    • neg: The number has a minus sign.
    • nr: The number of bytes in the number.
    • ok: false if s is not a number

    parse_quaternion128 ¶

    parse_quaternion128 :: proc(str: string, n: ^int = nil) -> (value: quaternion128, ok: bool) {…}
     

    Parses a 128-bit quaternion from a string

    Inputs

    • str: The input string containing a 128-bit quaternion.
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil).
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_quaternion128_example :: proc() {
    	n: int
    	q, ok := strconv.parse_quaternion128("1+2i+3j+4k", &n)
    	fmt.printfln("%v %i %t", q, n, ok)
    
    	q, ok = strconv.parse_quaternion128("1+2i+3j+4k hellope", &n)
    	fmt.printfln("%v %i %t", q, n, ok)
    }
    
    Output:
    1+2i+3j+4k 10 true
    1+2i+3j+4k 10 false
    

    Returns

    • value: The parsed 128-bit quaternion.
    • ok: false if a quaternion could not be found, or if the input string contained more than just the quaternion.

    parse_quaternion256 ¶

    parse_quaternion256 :: proc(str: string, n: ^int = nil) -> (value: quaternion256, ok: bool) {…}
     

    Parses a 256-bit quaternion from a string

    Inputs

    • str: The input string containing a 256-bit quaternion.
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil).
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_quaternion256_example :: proc() {
    	n: int
    	q, ok := strconv.parse_quaternion256("1+2i+3j+4k", &n)
    	fmt.printfln("%v %i %t", q, n, ok)
    
    	q, ok = strconv.parse_quaternion256("1+2i+3j+4k hellope", &n)
    	fmt.printfln("%v %i %t", q, n, ok)
    }
    
    Output:
    1+2i+3j+4k 10 true
    1+2i+3j+4k 10 false
    

    Returns

    • value: The parsed 256-bit quaternion.
    • ok: false if a quaternion could not be found, or if the input string contained more than just the quaternion.

    parse_quaternion64 ¶

    parse_quaternion64 :: proc(str: string, n: ^int = nil) -> (value: quaternion64, ok: bool) {…}
     

    Parses a 64-bit quaternion from a string

    Inputs

    • str: The input string containing a 64-bit quaternion.
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil).
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_quaternion64_example :: proc() {
    	n: int
    	q, ok := strconv.parse_quaternion64("1+2i+3j+4k", &n)
    	fmt.printfln("%v %i %t", q, n, ok)
    
    	q, ok = strconv.parse_quaternion64("1+2i+3j+4k hellope", &n)
    	fmt.printfln("%v %i %t", q, n, ok)
    }
    
    Output:
    1+2i+3j+4k 10 true
    1+2i+3j+4k 10 false
    

    Returns

    • value: The parsed 64-bit quaternion.
    • ok: false if a quaternion could not be found, or if the input string contained more than just the quaternion.

    parse_u128_maybe_prefixed ¶

    parse_u128_maybe_prefixed :: proc(str: string, n: ^int = nil) -> (value: u128, ok: bool) {…}
     

    Parses an unsigned integer value from a string in base 10, unless there's a prefix

    Inputs

    • str: The input string containing the integer value
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_u128_maybe_prefixed_example :: proc() {
    	n, ok := strconv.parse_u128_maybe_prefixed("1234")
    	fmt.println(n, ok)
    
    	n, ok = strconv.parse_u128_maybe_prefixed("5678eeee")
    	fmt.println(n, ok)
    }
    
    Output:
    1234 true
    5678 false
    

    Returns

    • value: The parsed u128 value
    • ok: false if a valid integer could not be found, if the value was negative, or if the input string contained more than just the number.

    parse_u128_of_base ¶

    parse_u128_of_base :: proc(str: string, base: int, n: ^int = nil) -> (value: u128, ok: bool) {…}
     

    Parses an unsigned integer value from a string in the given base, without any prefix

    Inputs

    • str: The input string containing the integer value
    • base: The base (radix) to use for parsing the integer (1-16)
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_u128_of_base_example :: proc() {
    	n, ok := strconv.parse_u128_of_base("1234eeee", 10)
    	fmt.println(n, ok)
    
    	n, ok = strconv.parse_u128_of_base("5678eeee", 16)
    	fmt.println(n, ok)
    }
    
    Output:
    1234 false
    1450766062 true
    

    Returns

    • value: The parsed u128 value
    • ok: false if no numeric value of the appropriate base could be found, or if the input string contained more than just the number.

    parse_u64_maybe_prefixed ¶

    parse_u64_maybe_prefixed :: proc(str: string, n: ^int = nil) -> (value: u64, ok: bool) {…}
     

    Parses an unsigned 64-bit integer value from the input string, using the specified base or inferring the base from a prefix

    Inputs

    • str: The input string to parse
    • base: The base of the number system to use for parsing (default: 0)
      • If base is 0, it will be inferred based on the prefix in the input string (e.g. '0x' for hexadecimal)
      • If base is not 0, it will be used for parsing regardless of any prefix in the input string
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_u64_maybe_prefixed_example :: proc() {
    	n, ok := strconv.parse_u64_maybe_prefixed("1234")
    	fmt.println(n,ok)
    
    	n, ok = strconv.parse_u64_maybe_prefixed("0xee")
    	fmt.println(n,ok)
    }
    
    Output:
    1234 true
    238 true
    

    Returns

    • value: The parsed uint64 value
    • ok: ok=false if a valid integer could not be found, if the value was negative, or if the input string contained more than just the number.

    parse_u64_of_base ¶

    parse_u64_of_base :: proc(str: string, base: int, n: ^int = nil) -> (value: u64, ok: bool) {…}
     

    Parses an unsigned 64-bit integer value from the input string without a prefix, using the specified base

    Inputs

    • str: The input string to parse
    • base: The base of the number system to use for parsing
      • Must be between 1 and 16 (inclusive)
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_u64_of_base_example :: proc() {
    	n, ok := strconv.parse_u64_of_base("1234e3", 10)
    	fmt.println(n,ok)
    
    	n, ok = strconv.parse_u64_of_base("5678eee",16)
    	fmt.println(n,ok)
    }
    
    Output:
    1234 false
    90672878 true
    

    Returns

    • value: The parsed uint64 value
    • ok: A boolean indicating whether the parsing was successful

    parse_uint ¶

    parse_uint :: proc(s: string, base: int = 0, n: ^int = nil) -> (value: uint, ok: bool) {…}
     

    Parses an unsigned integer value from the input string, using the specified base or inferring the base from a prefix

    Inputs

    • s: The input string to parse
    • base: The base of the number system to use for parsing (default: 0, inferred)
      • If base is 0, it will be inferred based on the prefix in the input string (e.g. '0x' for hexadecimal)
      • If base is not 0, it will be used for parsing regardless of any prefix in the input string
    • n: An optional pointer to an int to store the length of the parsed substring (default: nil)
    Example:
    import "core:fmt"
    import "core:strconv"
    parse_uint_example :: proc() {
    	n, ok := strconv.parse_uint("1234") // without prefix, inferred base 10
    	fmt.println(n,ok)
    
    	n, ok = strconv.parse_uint("ffff", 16) // without prefix, explicit base
    	fmt.println(n,ok)
    
    	n, ok = strconv.parse_uint("0xffff") // with prefix and inferred base
    	fmt.println(n,ok)
    }
    
    Output:
    1234 true
    65535 true
    65535 true
    

    Returns

    value: The parsed uint value ok: false if no appropriate value could be found; the value was negative; he input string contained more than just the number

    quote ¶

    Deprecated. This will almost certainly not do what you are expecting. If you actually meant to call this, call [quote_weird](#quote_weird) instead. Otherwise, you are probably looking for [quote_string](#quote_string).
    @(deprecated="This will almost certainly not do what you are expecting. If you actually meant to call this, call `quote_weird` instead. Otherwise, you are probably looking for `quote_string`.")
    quote :: proc(buf: []u8, str: string) -> string {…}

    quote_rune ¶

    quote_rune :: proc(
    	buf:     []u8, 
    	r:       rune, 
    	options: bit_set[Rune_Escaping_Option] = nil, 
    ) -> (result: string, ok: bool) #optional_ok {…}
     

    Writes a quoted rune representation of the input rune, encoded as UTF-8, to a given byte slice and returns the result as a string.

    Inputs

    • buf: The byte slice to which the quoted rune will be written.
    • r: The input rune to be quoted.
    • options: Controls how characters in the string are escaped.

    Returns

    • result: On success, the resulting string after writing the quoted rune representation. Otherwise, the procedure will return "" instead.
    • ok: true on success; false if buf was not large enough.

    Remarks

    The rune is quoted such that it would parse back as a valid rune literal in Odin syntax.

    This implies that single quotes (') are used.

    Example:
    import "core:fmt"
    import "core:strconv"
    quote_rune_example :: proc() {
    	buf: [4]byte
    	result := strconv.quote_rune(buf[:], 'A')
    	fmt.println(result, buf)
    }
    
    Output:
    'A' [39, 65, 39, 0]
    

    quote_string16_buf ¶

    quote_string16_buf :: proc(
    	buf:     []u8, 
    	str:     string16, 
    	quote:   u8 = '"', 
    	options: bit_set[Rune_Escaping_Option] = nil, 
    ) -> (result: string, ok: bool) #optional_ok {…}
     

    Writes a quoted string representation of the UTF-16 input string to byte buffer buf, and returns the result as a string.

    The string is formatted such that it would parse back as the same string in Odin syntax.

    Note: The output string is encoded as UTF-8.

    Inputs

    • buf: The byte slice to which the quoted string will be written.
    • str: The input string to be quoted.
    • quote: The quote character used to surround the string. This character is also escaped when it is encountered in the string.
    • options: Controls how characters in the string are escaped.

    Returns

    • result: The resulting string after writing the quoted string representation.
    • ok: true on success; false if buf was not large enough.
    Example:
    import "core:fmt"
    import "core:strconv"
    quote_example :: proc() {
    	buf: [20]byte
    	result := strconv.quote_string_buf(buf[:], "hello")
    	fmt.println(result, buf)
    }
    
    Output:
    "hello" [34, 104, 101, 108, 108, 111, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    

    quote_string16_dynamic_array ¶

    quote_string16_dynamic_array :: proc(
    	buf:     ^[dynamic]u8, 
    	str:     string16, 
    	quote:   u8 = '"', 
    	options: bit_set[Rune_Escaping_Option] = nil, 
    	loc := #caller_location, 
    ) -> (result: string, err: runtime.Allocator_Error) #optional_ok {…}
     

    Appends a quoted string representation of the UTF-16 input string to the end of buf, and returns the appended part as a string.

    The string is formatted such that it would parse back as the same string in Odin syntax.

    Note: The output string is encoded as UTF-8.

    Inputs

    • buf: The dynamic array to which the quoted string will be appended.
    • str: The input string to be quoted.
    • quote: The quote character used to surround the string. This character is also escaped when it is encountered in the string.
    • options: Controls how characters in the string are escaped.

    Returns

    • result: The resulting string after writing the quoted string representation.
    • err: Allocator error if one occurred, otherwise nil.
    Example:
    import "core:fmt"
    import "core:strconv"
    quote_example :: proc() {
    	buf: [dynamic]byte
    	result := strconv.quote_string_dynamic_array(&buf, "hello")
    	fmt.println(result, buf)
    }
    
    Output:
    "hello" [34, 104, 101, 108, 108, 111, 34]
    

    quote_string_buf ¶

    quote_string_buf :: proc(
    	buf:     []u8, 
    	str:     string, 
    	quote:   u8 = '"', 
    	options: bit_set[Rune_Escaping_Option] = nil, 
    ) -> (result: string, ok: bool) #optional_ok {…}
     

    Writes a quoted string representation of the input string to byte buffer buf, and returns the result as a string.

    The string is formatted such that it would parse back as the same string in Odin syntax.

    Inputs

    • buf: The byte slice to which the quoted string will be written.
    • str: The input string to be quoted.
    • quote: The quote character used to surround the string. This character is also escaped when it is encountered in the string.
    • options: Controls how characters in the string are escaped.

    Returns

    • result: The resulting string after writing the quoted string representation.
    • ok: true on success; false if buf was not large enough.
    Example:
    import "core:fmt"
    import "core:strconv"
    quote_example :: proc() {
    	buf: [20]byte
    	result := strconv.quote_string_buf(buf[:], "hello")
    	fmt.println(result, buf)
    }
    
    Output:
    "hello" [34, 104, 101, 108, 108, 111, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    

    quote_string_dynamic_array ¶

    quote_string_dynamic_array :: proc(
    	buf:     ^[dynamic]u8, 
    	str:     string, 
    	quote:   u8 = '"', 
    	options: bit_set[Rune_Escaping_Option] = nil, 
    	loc := #caller_location, 
    ) -> (result: string, err: runtime.Allocator_Error) #optional_ok {…}
     

    Appends a quoted string representation of the input string to the end of buf, and returns the appended part as a string.

    The string is formatted such that it would parse back as the same string in Odin syntax.

    Inputs

    • buf: The dynamic array to which the quoted string will be appended.
    • str: The input string to be quoted.
    • quote: The quote character used to surround the string. This character is also escaped when it is encountered in the string.
    • options: Controls how characters in the string are escaped.

    Returns

    • result: The resulting string after writing the quoted string representation.
    • err: Allocator error if one occurred, otherwise nil.
    Example:
    import "core:fmt"
    import "core:strconv"
    quote_example :: proc() {
    	buf: [dynamic]byte
    	result := strconv.quote_string_dynamic_array(&buf, "hello")
    	fmt.println(result, buf)
    }
    
    Output:
    "hello" [34, 104, 101, 108, 108, 111, 34]
    

    quote_weird ¶

    quote_weird :: proc(buf: []u8, str: string) -> string {…}
     

    Writes a quoted string representation of the input string to a given byte slice and returns the result as a string

    Inputs

    • buf: The byte slice to which the quoted string will be written
    • str: The input string to be quoted

    !! ISSUE !! NOT EXPECTED -- "\"hello\"" was expected

    Example:
    import "core:fmt"
    import "core:strconv"
    quote_example :: proc() {
    	buf: [20]byte
    	result := strconv.quote(buf[:], "hello")
    	fmt.println(result, buf)
    }
    
    Output:
    "'h''e''l''l''o'" [34, 39, 104, 39, 39, 101, 39, 39, 108, 39, 39, 108, 39, 39, 111, 39, 34, 0, 0, 0]
    

    Returns

    • The resulting string after writing the quoted string representation

    read4_to_u32 ¶

    read4_to_u32 :: proc "contextless" (s: string, i: int) -> u32 {…}

    read8_to_u64 ¶

    read8_to_u64 :: proc "contextless" (s: string, i: int) -> u64 {…}
     

    Loads 8 bytes starting at s[i] in little-endian order

    read_significant_digits ¶

    @(cold)
    read_significant_digits :: proc "contextless" (
    	s:                     string, 
    	i, end, int_digits, e: int, 
    ) -> (mantissa: u64, exp: int, trunc: bool) {…}
     

    Reads the first 19 significant digits of a decimal number again. The scanner uses it only if the number has more than 19 digits, because then the mantissa can overflow.

    Inputs

    • s, i: The input, and the position of the first digit before the ..
    • end: The position after the last digit.
    • int_digits: The number of digits before the ..
    • e: The exponent after the e, or 0.

    Returns

    • mantissa, exp: The value is mantissa * 10^exp, without the digits that were not read again.
    • trunc: true if the procedure did not read all the digits again.

    round_shortest ¶

    round_shortest :: proc(d: ^strconv_decimal.Decimal, mant: u64, exp: int, flt: ^Float_Info) {…}
     

    Rounds the given decimal number to its shortest representation, considering the provided floating-point format

    Inputs

    • d: The decimal number to round
    • mant: The mantissa of the floating-point number
    • exp: The exponent of the floating-point number
    • flt: Pointer to the Float_Info structure containing information about the floating-point format

    scan_hex_float ¶

    scan_hex_float :: proc "contextless" (s: string) -> (mantissa: u64, exp: int, neg, trunc: bool, nr: int, ok: bool) {…}
     

    Scans a hexadecimal floating-point number at the start of s. [+-] 0x hexdigits [. hexdigits] (p|P) [+-] digits A _ between digits is skipped

    Returns

    • mantissa, exp: The value is mantissa * 2^exp. If trunc is true, the significant hex digits after the first 16 were dropped, and at least one of them was not zero.
    • neg: The number has a minus sign.
    • nr: The number of bytes in the number.
    • ok: false if s does not start with a hexadecimal float.

    unquote_char ¶

    unquote_char :: proc(
    	str:   string, 
    	quote: u8, 
    ) -> (r: rune, multiple_bytes: bool, tail_string: string, success: bool) {…}
     

    Unquotes a single character from the input string, considering the given quote character

    Inputs

    • str: The input string containing the character to unquote
    • quote: The quote character to consider (e.g., '"')
    Example:
    import "core:fmt"
    import "core:strconv"
    unquote_char_example :: proc() {
    	src:="\'The\' raven"
    	r, multiple_bytes, tail_string, success  := strconv.unquote_char(src,'\'')
    	fmt.println("Source:", src)
    	fmt.printf("r: <%v>, multiple_bytes:%v, tail_string:<%s>, success:%v\n",r, multiple_bytes, tail_string, success)
    }
    
    Output:
    Source: 'The' raven
    r: <'>, multiple_bytes:false, tail_string:<The' raven>, success:true
    

    Returns

    • r: The unquoted rune
    • multiple_bytes: A boolean indicating if the rune has multiple bytes
    • tail_string: The remaining portion of the input string after unquoting the character
    • success: A boolean indicating whether the unquoting was successful

    unquote_string ¶

    unquote_string :: proc(
    	lit:       string, 
    	allocator := context.allocator, 
    ) -> (res: string, allocated, success: bool) {…}
     

    Unquotes the input string considering any type of quote character and returns the unquoted string

    Inputs

    • lit: The input string to unquote
    • allocator: (default: context.allocator)

    WARNING: This procedure gives unexpected results if the quotes are not the first and last characters.

    Example:
    import "core:fmt"
    import "core:strconv"
    unquote_string_example :: proc() {
    	src:="\"The raven Huginn is black.\""
    	s, allocated, ok := strconv.unquote_string(src)
    	fmt.println(src)
    	fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n\n", s, allocated, ok)
    
    	src="\'The raven Huginn\' is black."
    	s, allocated, ok = strconv.unquote_string(src)
    	fmt.println(src)
    	fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n\n", s, allocated, ok)
    
    	src="The raven \'Huginn\' is black."
    	s, allocated, ok = strconv.unquote_string(src) // Will produce undesireable results
    	fmt.println(src)
    	fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n", s, allocated, ok)
    }
    
    Output:
    "The raven Huginn is black."
    Unquoted: <The raven Huginn is black.>, alloc:false, ok:true
    
    'The raven Huginn' is black.
    Unquoted: <The raven Huginn' is black>, alloc:false, ok:true
    
    The raven 'Huginn' is black.
    Unquoted: <he raven 'Huginn' is black>, alloc:false, ok:true
    

    Returns

    • res: The resulting unquoted string
    • allocated: A boolean indicating if the resulting string was allocated using the provided allocator
    • success: A boolean indicating whether the unquoting was successful

    NOTE: If unquoting is unsuccessful, the allocated memory for the result will be freed.

    write_bits ¶

    write_bits :: proc(
    	buf:       []u8, 
    	x:         u64, 
    	base:      int, 
    	is_signed: bool, 
    	bit_size:  int, 
    	digits:    string, 
    	flags:     bit_set[Int_Flag], 
    ) -> string {…}
     

    Writes the string representation of an integer to a buffer with specified base, flags, and digit set.

    Inputs

    • buf: The buffer to append the integer representation to
    • x: The integer value to convert
    • base: The base for the integer representation (2 <= base <= MAX_BASE)
    • is_signed: A boolean indicating if the input should be treated as a signed integer
    • bit_size: The bit size of the signed integer representation (8, 16, 32, or 64)
    • digits: The digit set used for the integer representation
    • flags: The Int_Flags bit set to control integer formatting

    Returns

    • The string containing the integer representation appended to the buffer

    write_bits_128 ¶

    write_bits_128 :: proc(
    	buf:       []u8, 
    	x:         u128, 
    	base:      int, 
    	is_signed: bool, 
    	bit_size:  int, 
    	digits:    string, 
    	flags:     bit_set[Int_Flag], 
    ) -> string {…}
     

    Writes the string representation of a 128-bit integer to a buffer with specified base, flags, and digit set.

    Inputs

    • buf: The buffer to append the integer representation to
    • x: The 128-bit integer value to convert
    • base: The base for the integer representation (2 <= base <= MAX_BASE)
    • is_signed: A boolean indicating if the input should be treated as a signed integer
    • bit_size: The bit size of the signed integer representation (8, 16, 32, 64, or 128)
    • digits: The digit set used for the integer representation
    • flags: The Int_Flags bit set to control integer formatting

    Returns

    • The string containing the integer representation written to the buffer

    write_bool ¶

    write_bool :: proc(buf: []u8, b: bool) -> string {…}
     

    Writes a boolean value as a string to the given buffer

    Inputs

    • buf: The buffer to write the boolean value to
    • b: The boolean value to be written
    Example:
    import "core:fmt"
    import "core:strconv"
    write_bool_example :: proc() {
    	buf: [6]byte
    	result := strconv.write_bool(buf[:], true)
    	fmt.println(result, buf)
    }
    
    Output:
    true [116, 114, 117, 101, 0, 0]
    

    Returns

    • The resulting string after writing the boolean value

    write_float ¶

    write_float :: proc(
    	buf:            []u8, 
    	f:              f64, 
    	fmt:            u8, 
    	prec, bit_size: int, 
    	flags:          bit_set[Float_Flag] = {.Plus}, 
    ) -> string {…}
     

    ftoa C name deprecated, use write_float instead (same procedure)

    Writes a float64 value as a string to the given buffer with the specified format and precision

    Inputs

    • buf: The buffer to write the float64 value to
    • f: The float64 value to be written
    • fmt: The byte specifying the format to use for the conversion
    • prec: The precision to use for the conversion
    • bit_size: The size of the float in bits (16, 32, or 64)
    • flags: Additional formatting options. The default value adds a '+' sign for positive finite values, for compatibility reasons.
    Example:
    import "core:fmt"
    import "core:strconv"
    write_float_example :: proc() {
    	buf: [8]byte
    	result := strconv.write_float(buf[:], 3.14159, 'f', 2, 64)
    	fmt.println(result, buf)
    }
    
    Output:
    +3.14 [43, 51, 46, 49, 52, 0, 0, 0]
    

    Pass nil for flags to format the same value as 3.14.

    Returns

    • The resulting string after writing the float

    write_int ¶

    write_int :: proc(buf: []u8, i: i64, base: int) -> string {…}
     

    Writes a signed integer value as a string to the given buffer with the specified base

    Inputs

    • buf: The buffer to write the signed integer value to
    • i: The signed integer value to be written
    • base: The base to use for converting the integer value
    Example:
    import "core:fmt"
    import "core:strconv"
    write_int_example :: proc() {
    	buf: [4]byte
    	result := strconv.write_int(buf[:], -42, 10)
    	fmt.println(result, buf)
    }
    
    Output:
    -42 [45, 52, 50, 0]
    

    Returns

    • The resulting string after writing the signed integer value

    write_string ¶

    write_string :: proc(buf: []u8, str: string) -> (result: string, ok: bool) #optional_ok {…}
     

    Writes string str to byte buffer buf, and returns the written bytes as a string.

    Inputs

    • buf: The byte slice to which the quoted string will be written.
    • str: The input string to be quoted.

    Returns

    • result: The resulting string after writing it to the buffer. May be clipped if buf was not large enough.
    • ok: true on success; false if buf was not large enough.
    Example:
    import "core:fmt"
    import "core:strconv"
    quote_example :: proc() {
    	buf: [20]byte
    	result := strconv.quote_string_buf(buf[:], "hello")
    	fmt.println(result, buf)
    }
    
    Output:
    "hello" [34, 104, 101, 108, 108, 111, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    

    write_string16_buf ¶

    write_string16_buf :: proc(
    	buf: []u8, 
    	str: string16, 
    ) -> (result: string, ok: bool) #optional_ok {…}
     

    Writes UTF-16 encoded string str, converted to UTF-8 to byte buffer buf, and returns the written bytes as a string.

    Inputs

    • buf: The byte slice to which the quoted string will be written.
    • str: The input string to be quoted.

    Returns

    • result: The resulting string after writing it to the buffer. May be clipped if buf was not large enough.
    • ok: true on success; false if buf was not large enough.

    Remarks

    Unpaired UTF-16 surrogates are encoded as the Unicode replacement character. The UTF-16 decoder does not distinguish malformed sequences from literal replacement characters, so both are written identically.

    Example:
    import "core:fmt"
    import "core:strconv"
    quote_example :: proc() {
    	buf: [20]byte
    	result := strconv.quote_string_buf(buf[:], "hello")
    	fmt.println(result, buf)
    }
    
    Output:
    "hello" [34, 104, 101, 108, 108, 111, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    

    write_string16_dynamic_array ¶

    write_string16_dynamic_array :: proc(
    	buf: ^[dynamic]u8, 
    	str: string16, 
    	loc := #caller_location, 
    ) -> (result: string, err: runtime.Allocator_Error) #optional_ok {…}
     

    Appends UTF-16 encoded string str, converted to UTF-8, to the end of buf, and returns appended bytes as a string.

    Inputs

    • buf: The byte slice to which the quoted string will be written.
    • str: The input string to be quoted.

    Returns

    • result: The resulting string after writing it to the buffer. May be clipped if buf was not large enough.
    • err: Allocator error if one occurred, otherwise nil.

    Remarks

    Unpaired UTF-16 surrogates are encoded as the Unicode replacement character. The UTF-16 decoder does not distinguish malformed sequences from literal replacement characters, so both are written identically.

    Example:
    import "core:fmt"
    import "core:strconv"
    quote_example :: proc() {
    	buf: [20]byte
    	result := strconv.quote_string_buf(buf[:], "hello")
    	fmt.println(result, buf)
    }
    
    Output:
    "hello" [34, 104, 101, 108, 108, 111, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    

    write_u128 ¶

    write_u128 :: proc(buf: []u8, u: u128, base: int) -> string {…}

    write_uint ¶

    write_uint :: proc(buf: []u8, u: u64, base: int) -> string {…}
     

    Writes an unsigned integer value as a string to the given buffer with the specified base

    Inputs

    • buf: The buffer to write the unsigned integer value to
    • u: The unsigned integer value to be written
    • base: The base to use for converting the integer value
    Example:
    import "core:fmt"
    import "core:strconv"
    write_uint_example :: proc() {
    	buf: [4]byte
    	result := strconv.write_uint(buf[:], 42, 16)
    	fmt.println(result, buf)
    }
    
    Output:
    2a [50, 97, 0, 0]
    

    Returns

    • The resulting string after writing the unsigned integer value

    Procedure Groups

    quote_string ¶

    quote_string :: proc{
    	quote_string_buf,
    	quote_string_dynamic_array,
    }
    
     

    Writes a quoted string representation of the input string to a given byte buffer, and returns the result as a string.

    The string is formatted such that it would parse back as the same string in Odin syntax.

    quote_string16 ¶

    quote_string16 :: proc{
    	quote_string16_buf,
    	quote_string16_dynamic_array,
    }
    
     

    Writes a quoted string representation of the UTF-16 input string, converted to UTF-8, to a given byte buffer, and returns the result as a string.

    The string is formatted such that it would parse back as the same string in Odin syntax.

    `#config` values

    Source Files

    Generation Information

    Generated with odin version dev-2026-11 (vendor "odin") Windows_amd64 @ 2026-11-18 21:05:19.828955300 +0000 UTC