mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 13:00:28 +00:00
Remove trailing whitespace
This commit is contained in:
@@ -12,11 +12,11 @@ Decimal :: struct {
|
||||
Sets a Decimal from a given string `s`. The string is expected to represent a float. Stores parsed number in the given Decimal structure.
|
||||
If parsing fails, the Decimal will be left in an undefined state.
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- d: Pointer to a Decimal struct where the parsed result will be stored
|
||||
- s: The input string representing the floating-point number
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- ok: A boolean indicating whether the parsing was successful
|
||||
*/
|
||||
set :: proc(d: ^Decimal, s: string) -> (ok: bool) {
|
||||
@@ -104,11 +104,11 @@ set :: proc(d: ^Decimal, s: string) -> (ok: bool) {
|
||||
/*
|
||||
Converts a Decimal to a string representation, using the provided buffer as storage.
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- buf: A byte slice buffer to hold the resulting string
|
||||
- a: The struct to be converted to a string
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- A string representation of the Decimal
|
||||
*/
|
||||
decimal_to_string :: proc(buf: []byte, a: ^Decimal) -> string {
|
||||
@@ -150,7 +150,7 @@ decimal_to_string :: proc(buf: []byte, a: ^Decimal) -> string {
|
||||
/*
|
||||
Trims trailing zeros in the given Decimal, updating the count and decimal_point values as needed.
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: Pointer to the Decimal struct to be trimmed
|
||||
*/
|
||||
trim :: proc(a: ^Decimal) {
|
||||
@@ -166,7 +166,7 @@ Converts a given u64 integer `idx` to its Decimal representation in the provided
|
||||
|
||||
**Used for internal Decimal Operations.**
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: Where the result will be stored
|
||||
- idx: The value to be assigned to the Decimal
|
||||
*/
|
||||
@@ -190,11 +190,11 @@ assign :: proc(a: ^Decimal, idx: u64) {
|
||||
trim(a)
|
||||
}
|
||||
/*
|
||||
Shifts the Decimal value to the right by k positions.
|
||||
Shifts the Decimal value to the right by k positions.
|
||||
|
||||
**Used for internal Decimal Operations.**
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: The Decimal struct to be shifted
|
||||
- k: The number of positions to shift right
|
||||
*/
|
||||
@@ -344,7 +344,7 @@ Shifts the decimal of the input value to the left by `k` places
|
||||
|
||||
WARNING: asserts `k < 61`
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: The Decimal to be modified
|
||||
- k: The number of places to shift the decimal to the left
|
||||
*/
|
||||
@@ -405,7 +405,7 @@ shift_left :: proc(a: ^Decimal, k: uint) #no_bounds_check {
|
||||
/*
|
||||
Shifts the decimal of the input value by the specified number of places
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: The Decimal to be modified
|
||||
- i: The number of places to shift the decimal (positive for left shift, negative for right shift)
|
||||
*/
|
||||
@@ -435,7 +435,7 @@ shift :: proc(a: ^Decimal, i: int) {
|
||||
/*
|
||||
Determines if the Decimal can be rounded up at the given digit index
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: The Decimal to check
|
||||
- nd: The digit index to consider for rounding up
|
||||
|
||||
@@ -455,7 +455,7 @@ can_round_up :: proc(a: ^Decimal, nd: int) -> bool {
|
||||
/*
|
||||
Rounds the Decimal at the given digit index
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: The Decimal to be modified
|
||||
- nd: The digit index to round
|
||||
*/
|
||||
@@ -470,7 +470,7 @@ round :: proc(a: ^Decimal, nd: int) {
|
||||
/*
|
||||
Rounds the Decimal up at the given digit index
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: The Decimal to be modified
|
||||
- nd: The digit index to round up
|
||||
*/
|
||||
@@ -493,7 +493,7 @@ round_up :: proc(a: ^Decimal, nd: int) {
|
||||
/*
|
||||
Rounds down the decimal value to the specified number of decimal places
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: The Decimal value to be rounded down
|
||||
- nd: The number of decimal places to round down to
|
||||
|
||||
@@ -522,7 +522,7 @@ round_down :: proc(a: ^Decimal, nd: int) {
|
||||
/*
|
||||
Extracts the rounded integer part of a decimal value
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- a: A pointer to the Decimal value to extract the rounded integer part from
|
||||
|
||||
WARNING: There are no guarantees about overflow.
|
||||
|
||||
@@ -23,7 +23,7 @@ _f64_info := Float_Info{52, 11, -1023}
|
||||
/*
|
||||
Converts a floating-point number to a string with the specified format and precision.
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
|
||||
buf: A byte slice to store the resulting string
|
||||
val: The floating-point value to be converted
|
||||
@@ -40,7 +40,7 @@ Example:
|
||||
bit_size := 64
|
||||
result := strconv.generic_ftoa(buf[:], val, fmt, precision, bit_size) -> "3.14"
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- A byte slice containing the formatted string
|
||||
*/
|
||||
generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, precision, bit_size: int) -> []byte {
|
||||
@@ -122,7 +122,7 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, precision, bit_size: int)
|
||||
/*
|
||||
Converts a decimal floating-point number into a byte buffer with the given format
|
||||
|
||||
**Inputs**
|
||||
**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
|
||||
@@ -130,7 +130,7 @@ Converts a decimal floating-point number into a byte buffer with the given forma
|
||||
- precision: The number of digits after the decimal point
|
||||
- fmt: The format specifier (accepted values: 'f', 'F', 'e', 'E', 'g', 'G')
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- A byte slice containing the formatted decimal floating-point number
|
||||
*/
|
||||
format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slice, precision: int, fmt: byte) -> []byte {
|
||||
@@ -256,7 +256,7 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slic
|
||||
/*
|
||||
Rounds the given decimal number to its shortest representation, considering the provided floating-point format
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- d: The decimal number to round
|
||||
- mant: The mantissa of the floating-point number
|
||||
- exp: The exponent of the floating-point number
|
||||
@@ -331,11 +331,11 @@ round_shortest :: proc(d: ^decimal.Decimal, mant: u64, exp: int, flt: ^Float_Inf
|
||||
/*
|
||||
Converts a decimal number to its floating-point representation with the given format and returns the resulting bits
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- d: Pointer to the decimal number to convert
|
||||
- info: Pointer to the Float_Info structure containing information about the floating-point format
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- b: The bits representing the floating-point number
|
||||
- overflow: A boolean indicating whether an overflow occurred during conversion
|
||||
*/
|
||||
|
||||
@@ -12,12 +12,12 @@ digits := "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
/*
|
||||
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**
|
||||
**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**
|
||||
**Returns**
|
||||
- u: The absolute value of the input integer
|
||||
- neg: A boolean indicating whether the input integer is negative
|
||||
*/
|
||||
@@ -50,7 +50,7 @@ is_integer_negative :: proc(x: u64, is_signed: bool, bit_size: int) -> (u: u64,
|
||||
/*
|
||||
Writes the string representation of an integer to a buffer with specified base, flags, and digit set.
|
||||
|
||||
**Inputs**
|
||||
**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)
|
||||
@@ -59,7 +59,7 @@ Writes the string representation of an integer to a buffer with specified base,
|
||||
- digits: The digit set used for the integer representation
|
||||
- flags: The Int_Flags bit set to control integer formatting
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The string containing the integer representation appended to the buffer
|
||||
*/
|
||||
write_bits :: proc(buf: []byte, x: u64, base: int, is_signed: bool, bit_size: int, digits: string, flags: Int_Flags) -> string {
|
||||
@@ -106,12 +106,12 @@ write_bits :: proc(buf: []byte, x: u64, base: int, is_signed: bool, bit_size: in
|
||||
/*
|
||||
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**
|
||||
**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**
|
||||
**Returns**
|
||||
- u: The absolute value of the input integer
|
||||
- neg: A boolean indicating whether the input integer is negative
|
||||
*/
|
||||
@@ -148,7 +148,7 @@ is_integer_negative_128 :: proc(x: u128, is_signed: bool, bit_size: int) -> (u:
|
||||
/*
|
||||
Writes the string representation of a 128-bit integer to a buffer with specified base, flags, and digit set.
|
||||
|
||||
**Inputs**
|
||||
**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)
|
||||
@@ -157,7 +157,7 @@ Writes the string representation of a 128-bit integer to a buffer with specified
|
||||
- digits: The digit set used for the integer representation
|
||||
- flags: The Int_Flags bit set to control integer formatting
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The string containing the integer representation written to the buffer
|
||||
*/
|
||||
write_bits_128 :: proc(buf: []byte, x: u128, base: int, is_signed: bool, bit_size: int, digits: string, flags: Int_Flags) -> string {
|
||||
|
||||
@@ -5,8 +5,8 @@ import "decimal"
|
||||
/*
|
||||
Parses a boolean value from the input string
|
||||
|
||||
**Inputs**
|
||||
- s: 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)
|
||||
@@ -386,7 +386,7 @@ Parses an unsigned integer value from the input string, using the specified base
|
||||
- If base is not 0, it will be used for parsing regardless of any prefix in the input string
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
import "core:fmt"
|
||||
import "core:strconv"
|
||||
parse_uint_example :: proc() {
|
||||
@@ -399,14 +399,14 @@ Example:
|
||||
n, ok = strconv.parse_uint("0xffff") // with prefix and inferred base
|
||||
fmt.println(n,ok)
|
||||
}
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
1234 true
|
||||
65535 true
|
||||
65535 true
|
||||
|
||||
**Returns**
|
||||
**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
|
||||
@@ -423,7 +423,7 @@ parse_uint :: proc(s: string, base := 0, n: ^int = nil) -> (value: uint, ok: boo
|
||||
/*
|
||||
Parses an integer value from a string in the given base, without any prefix
|
||||
|
||||
**Inputs**
|
||||
**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)
|
||||
@@ -436,12 +436,12 @@ Example:
|
||||
n, ok := strconv.parse_i128_of_base("-1234eeee", 10)
|
||||
fmt.println(n,ok)
|
||||
}
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
-1234 false
|
||||
|
||||
**Returns**
|
||||
**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.
|
||||
*/
|
||||
@@ -491,7 +491,7 @@ parse_i128_of_base :: proc(str: string, base: int, n: ^int = nil) -> (value: i12
|
||||
/*
|
||||
Parses an integer value from a string in base 10, unless there's a prefix
|
||||
|
||||
**Inputs**
|
||||
**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)
|
||||
|
||||
@@ -506,13 +506,13 @@ Example:
|
||||
n, ok = strconv.parse_i128_maybe_prefixed("0xeeee")
|
||||
fmt.println(n, ok)
|
||||
}
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
1234 true
|
||||
61166 true
|
||||
|
||||
**Returns**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -574,7 +574,7 @@ parse_i128 :: proc{parse_i128_maybe_prefixed, parse_i128_of_base}
|
||||
/*
|
||||
Parses an unsigned integer value from a string in the given base, without any prefix
|
||||
|
||||
**Inputs**
|
||||
**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)
|
||||
@@ -590,13 +590,13 @@ Example:
|
||||
n, ok = strconv.parse_u128_of_base("5678eeee", 16)
|
||||
fmt.println(n, ok)
|
||||
}
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
1234 false
|
||||
1450766062 true
|
||||
|
||||
**Returns**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -634,7 +634,7 @@ parse_u128_of_base :: proc(str: string, base: int, n: ^int = nil) -> (value: u12
|
||||
/*
|
||||
Parses an unsigned integer value from a string in base 10, unless there's a prefix
|
||||
|
||||
**Inputs**
|
||||
**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)
|
||||
|
||||
@@ -649,13 +649,13 @@ Example:
|
||||
n, ok = strconv.parse_u128_maybe_prefixed("5678eeee")
|
||||
fmt.println(n, ok)
|
||||
}
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
1234 true
|
||||
5678 false
|
||||
|
||||
**Returns**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -706,10 +706,10 @@ parse_u128 :: proc{parse_u128_maybe_prefixed, parse_u128_of_base}
|
||||
/*
|
||||
Converts a byte to lowercase
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- ch: A byte character to be converted to lowercase.
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- A lowercase byte character.
|
||||
*/
|
||||
@(private)
|
||||
@@ -717,7 +717,7 @@ lower :: #force_inline proc "contextless" (ch: byte) -> byte { return ('a' - 'A'
|
||||
/*
|
||||
Parses a 32-bit floating point number from a string
|
||||
|
||||
**Inputs**
|
||||
**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).
|
||||
|
||||
@@ -732,13 +732,13 @@ Example:
|
||||
n, ok = strconv.parse_f32("5678e2")
|
||||
fmt.printfln("%.3f %v", n, ok)
|
||||
}
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
0.000 false
|
||||
567800.000 true
|
||||
|
||||
**Returns**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -750,7 +750,7 @@ parse_f32 :: proc(s: string, n: ^int = nil) -> (value: f32, ok: bool) {
|
||||
/*
|
||||
Parses a 64-bit floating point number from a string
|
||||
|
||||
**Inputs**
|
||||
**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).
|
||||
|
||||
@@ -765,13 +765,13 @@ Example:
|
||||
n, ok = strconv.parse_f64("5678e2")
|
||||
fmt.printfln("%.3f %v", n, ok)
|
||||
}
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
0.000 false
|
||||
567800.000 true
|
||||
|
||||
**Returns**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -787,7 +787,7 @@ parse_f64 :: proc(str: string, n: ^int = nil) -> (value: f64, 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**
|
||||
**Inputs**
|
||||
- str: The input string containing a 32-bit floating point number.
|
||||
|
||||
Example:
|
||||
@@ -801,14 +801,14 @@ Example:
|
||||
n, _, ok = strconv.parse_f32_prefix("5678e2")
|
||||
fmt.printfln("%.3f %v", n, ok)
|
||||
}
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
0.000 false
|
||||
567800.000 true
|
||||
|
||||
|
||||
**Returns**
|
||||
|
||||
**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.
|
||||
@@ -822,7 +822,7 @@ parse_f32_prefix :: proc(str: string) -> (value: f32, 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**
|
||||
**Inputs**
|
||||
- str: The input string containing a 64-bit floating point number.
|
||||
|
||||
Example:
|
||||
@@ -846,7 +846,7 @@ Output:
|
||||
1234.000 true
|
||||
13.370 true
|
||||
|
||||
**Returns**
|
||||
**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
|
||||
@@ -1184,7 +1184,7 @@ parse_f64_prefix :: proc(str: string) -> (value: f64, nr: int, ok: bool) {
|
||||
/*
|
||||
Parses a 128-bit complex number from a string
|
||||
|
||||
**Inputs**
|
||||
**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).
|
||||
|
||||
@@ -1200,13 +1200,13 @@ Example:
|
||||
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**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -1232,12 +1232,12 @@ parse_complex128 :: proc(str: string, n: ^int = nil) -> (value: complex128, ok:
|
||||
}
|
||||
|
||||
value = complex(real_value, imag_value)
|
||||
return
|
||||
return
|
||||
}
|
||||
/*
|
||||
Parses a 64-bit complex number from a string
|
||||
|
||||
**Inputs**
|
||||
**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).
|
||||
|
||||
@@ -1253,13 +1253,13 @@ Example:
|
||||
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**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -1271,7 +1271,7 @@ parse_complex64 :: proc(str: string, n: ^int = nil) -> (value: complex64, ok: bo
|
||||
/*
|
||||
Parses a 32-bit complex number from a string
|
||||
|
||||
**Inputs**
|
||||
**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).
|
||||
|
||||
@@ -1287,13 +1287,13 @@ Example:
|
||||
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**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -1305,7 +1305,7 @@ parse_complex32 :: proc(str: string, n: ^int = nil) -> (value: complex32, ok: bo
|
||||
/*
|
||||
Parses a 256-bit quaternion from a string
|
||||
|
||||
**Inputs**
|
||||
**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).
|
||||
|
||||
@@ -1321,13 +1321,13 @@ Example:
|
||||
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**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -1385,7 +1385,7 @@ parse_quaternion256 :: proc(str: string, n: ^int = nil) -> (value: quaternion256
|
||||
/*
|
||||
Parses a 128-bit quaternion from a string
|
||||
|
||||
**Inputs**
|
||||
**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).
|
||||
|
||||
@@ -1401,13 +1401,13 @@ Example:
|
||||
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**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -1419,7 +1419,7 @@ parse_quaternion128 :: proc(str: string, n: ^int = nil) -> (value: quaternion128
|
||||
/*
|
||||
Parses a 64-bit quaternion from a string
|
||||
|
||||
**Inputs**
|
||||
**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).
|
||||
|
||||
@@ -1435,13 +1435,13 @@ Example:
|
||||
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**
|
||||
|
||||
**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.
|
||||
*/
|
||||
@@ -1450,10 +1450,10 @@ parse_quaternion64 :: proc(str: string, n: ^int = nil) -> (value: quaternion64,
|
||||
v, ok = parse_quaternion256(str, n)
|
||||
return cast(quaternion64)v, ok
|
||||
}
|
||||
/*
|
||||
/*
|
||||
Writes a boolean value as a string to the given buffer
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- buf: The buffer to write the boolean value to
|
||||
- b: The boolean value to be written
|
||||
|
||||
@@ -1471,7 +1471,7 @@ Output:
|
||||
|
||||
true [116, 114, 117, 101, 0, 0]
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The resulting string after writing the boolean value
|
||||
*/
|
||||
write_bool :: proc(buf: []byte, b: bool) -> string {
|
||||
@@ -1483,10 +1483,10 @@ write_bool :: proc(buf: []byte, b: bool) -> string {
|
||||
}
|
||||
return string(buf[:n])
|
||||
}
|
||||
/*
|
||||
/*
|
||||
Writes an unsigned integer value as a string to the given buffer with the specified base
|
||||
|
||||
**Inputs**
|
||||
**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
|
||||
@@ -1505,16 +1505,16 @@ Output:
|
||||
|
||||
2a [50, 97, 0, 0]
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The resulting string after writing the unsigned integer value
|
||||
*/
|
||||
write_uint :: proc(buf: []byte, u: u64, base: int) -> string {
|
||||
return write_bits(buf, u, base, false, 8*size_of(uint), digits, nil)
|
||||
}
|
||||
/*
|
||||
/*
|
||||
Writes a signed integer value as a string to the given buffer with the specified base
|
||||
|
||||
**Inputs**
|
||||
**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
|
||||
@@ -1533,7 +1533,7 @@ Output:
|
||||
|
||||
-42 [45, 52, 50, 0]
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The resulting string after writing the signed integer value
|
||||
*/
|
||||
write_int :: proc(buf: []byte, i: i64, base: int) -> string {
|
||||
@@ -1546,10 +1546,10 @@ write_u128 :: proc(buf: []byte, u: u128, base: int) -> string {
|
||||
return write_bits_128(buf, u, base, false, 8*size_of(uint), digits, nil)
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
Converts an integer value to a string and stores it in the given buffer
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- buf: The buffer to store the resulting string
|
||||
- i: The integer value to be converted
|
||||
|
||||
@@ -1567,7 +1567,7 @@ Output:
|
||||
|
||||
42 [52, 50, 0, 0]
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The resulting string after converting the integer value
|
||||
*/
|
||||
itoa :: proc(buf: []byte, i: int) -> string {
|
||||
@@ -1576,7 +1576,7 @@ itoa :: proc(buf: []byte, i: int) -> string {
|
||||
/*
|
||||
Converts a string to an integer value
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- s: The string to be converted
|
||||
|
||||
Example:
|
||||
@@ -1591,17 +1591,17 @@ Output:
|
||||
|
||||
42
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The resulting integer value
|
||||
*/
|
||||
atoi :: proc(s: string) -> int {
|
||||
v, _ := parse_int(s)
|
||||
return v
|
||||
}
|
||||
/*
|
||||
/*
|
||||
Converts a string to a float64 value
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- s: The string to be converted
|
||||
|
||||
Example:
|
||||
@@ -1616,7 +1616,7 @@ Output:
|
||||
|
||||
3.140
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The resulting float64 value after converting the string
|
||||
*/
|
||||
atof :: proc(s: string) -> f64 {
|
||||
@@ -1625,10 +1625,10 @@ atof :: proc(s: string) -> f64 {
|
||||
}
|
||||
// Alias to `write_float`
|
||||
ftoa :: write_float
|
||||
/*
|
||||
/*
|
||||
Writes a float64 value as a string to the given buffer with the specified format and precision
|
||||
|
||||
**Inputs**
|
||||
**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
|
||||
@@ -1649,7 +1649,7 @@ Output:
|
||||
|
||||
+3.14 [43, 51, 46, 49, 52, 0, 0, 0]
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The resulting string after writing the float
|
||||
*/
|
||||
write_float :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> string {
|
||||
@@ -1658,11 +1658,11 @@ write_float :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> stri
|
||||
/*
|
||||
Writes a quoted string representation of the input string to a given byte slice and returns the result as a string
|
||||
|
||||
**Inputs**
|
||||
**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
|
||||
!! ISSUE !! NOT EXPECTED -- "\"hello\"" was expected
|
||||
|
||||
Example:
|
||||
|
||||
@@ -1678,7 +1678,7 @@ 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**
|
||||
**Returns**
|
||||
- The resulting string after writing the quoted string representation
|
||||
*/
|
||||
quote :: proc(buf: []byte, str: string) -> string {
|
||||
@@ -1721,7 +1721,7 @@ quote :: proc(buf: []byte, str: string) -> string {
|
||||
/*
|
||||
Writes a quoted rune representation of the input rune to a given byte slice and returns the result as a string
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- buf: The byte slice to which the quoted rune will be written
|
||||
- r: The input rune to be quoted
|
||||
|
||||
@@ -1739,7 +1739,7 @@ Output:
|
||||
|
||||
'A' [39, 65, 39, 0]
|
||||
|
||||
**Returns**
|
||||
**Returns**
|
||||
- The resulting string after writing the quoted rune representation
|
||||
*/
|
||||
quote_rune :: proc(buf: []byte, r: rune) -> string {
|
||||
@@ -1800,11 +1800,11 @@ quote_rune :: proc(buf: []byte, r: rune) -> string {
|
||||
/*
|
||||
Unquotes a single character from the input string, considering the given quote character
|
||||
|
||||
**Inputs**
|
||||
**Inputs**
|
||||
- str: The input string containing the character to unquote
|
||||
- quote: The quote character to consider (e.g., '"')
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
import "core:fmt"
|
||||
import "core:strconv"
|
||||
@@ -1815,12 +1815,12 @@ Example:
|
||||
fmt.printf("r: <%v>, multiple_bytes:%v, tail_string:<%s>, success:%v\n",r, multiple_bytes, tail_string, success)
|
||||
}
|
||||
|
||||
Output:
|
||||
Output:
|
||||
|
||||
Source: 'The' raven
|
||||
r: <'>, multiple_bytes:false, tail_string:<The' raven>, success:true
|
||||
|
||||
**Returns**
|
||||
**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
|
||||
@@ -1923,13 +1923,13 @@ unquote_char :: proc(str: string, quote: byte) -> (r: rune, multiple_bytes: bool
|
||||
/*
|
||||
Unquotes the input string considering any type of quote character and returns the unquoted string
|
||||
|
||||
**Inputs**
|
||||
**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:
|
||||
Example:
|
||||
|
||||
import "core:fmt"
|
||||
import "core:strconv"
|
||||
@@ -1947,10 +1947,10 @@ Example:
|
||||
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)
|
||||
fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n", s, allocated, ok)
|
||||
}
|
||||
|
||||
Output:
|
||||
Output:
|
||||
|
||||
"The raven Huginn is black."
|
||||
Unquoted: <The raven Huginn is black.>, alloc:false, ok:true
|
||||
@@ -1961,7 +1961,7 @@ Output:
|
||||
The raven 'Huginn' is black.
|
||||
Unquoted: <he raven 'Huginn' is black>, alloc:false, ok:true
|
||||
|
||||
**Returns**
|
||||
**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
|
||||
@@ -2002,7 +2002,7 @@ unquote_string :: proc(lit: string, allocator := context.allocator) -> (res: str
|
||||
return s, false, true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
context.allocator = allocator
|
||||
|
||||
buf_len := 3*len(s) / 2
|
||||
|
||||
Reference in New Issue
Block a user