|
@@ -5,8 +5,8 @@ import "decimal"
|
|
/*
|
|
/*
|
|
Parses a boolean value from the input string
|
|
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"
|
|
- true: "1", "t", "T", "true", "TRUE", "True"
|
|
- false: "0", "f", "F", "false", "FALSE", "False"
|
|
- false: "0", "f", "F", "false", "FALSE", "False"
|
|
- n: An optional pointer to an int to store the length of the parsed substring (default: nil)
|
|
- 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
|
|
- If base is not 0, it will be used for parsing regardless of any prefix in the input string
|
|
|
|
|
|
Example:
|
|
Example:
|
|
-
|
|
|
|
|
|
+
|
|
import "core:fmt"
|
|
import "core:fmt"
|
|
import "core:strconv"
|
|
import "core:strconv"
|
|
parse_uint_example :: proc() {
|
|
parse_uint_example :: proc() {
|
|
@@ -399,14 +399,14 @@ Example:
|
|
n, ok = strconv.parse_uint("0xffff") // with prefix and inferred base
|
|
n, ok = strconv.parse_uint("0xffff") // with prefix and inferred base
|
|
fmt.println(n,ok)
|
|
fmt.println(n,ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
1234 true
|
|
1234 true
|
|
65535 true
|
|
65535 true
|
|
65535 true
|
|
65535 true
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+**Returns**
|
|
|
|
|
|
value: The parsed uint value
|
|
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
|
|
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
|
|
Parses an integer value from a string in the given base, without any prefix
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- str: The input string containing the integer value
|
|
- str: The input string containing the integer value
|
|
- base: The base (radix) to use for parsing the integer (1-16)
|
|
- 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)
|
|
- 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)
|
|
n, ok := strconv.parse_i128_of_base("-1234eeee", 10)
|
|
fmt.println(n,ok)
|
|
fmt.println(n,ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
-1234 false
|
|
-1234 false
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+**Returns**
|
|
- value: The parsed i128 value
|
|
- 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.
|
|
- 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
|
|
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
|
|
- 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)
|
|
- 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")
|
|
n, ok = strconv.parse_i128_maybe_prefixed("0xeeee")
|
|
fmt.println(n, ok)
|
|
fmt.println(n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
1234 true
|
|
1234 true
|
|
61166 true
|
|
61166 true
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed i128 value
|
|
- 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.
|
|
- 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
|
|
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
|
|
- str: The input string containing the integer value
|
|
- base: The base (radix) to use for parsing the integer (1-16)
|
|
- 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)
|
|
- 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)
|
|
n, ok = strconv.parse_u128_of_base("5678eeee", 16)
|
|
fmt.println(n, ok)
|
|
fmt.println(n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
1234 false
|
|
1234 false
|
|
1450766062 true
|
|
1450766062 true
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed u128 value
|
|
- 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.
|
|
- 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
|
|
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
|
|
- 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)
|
|
- 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")
|
|
n, ok = strconv.parse_u128_maybe_prefixed("5678eeee")
|
|
fmt.println(n, ok)
|
|
fmt.println(n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
1234 true
|
|
1234 true
|
|
5678 false
|
|
5678 false
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed u128 value
|
|
- 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.
|
|
- 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
|
|
Converts a byte to lowercase
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- ch: A byte character to be converted to lowercase.
|
|
- ch: A byte character to be converted to lowercase.
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+**Returns**
|
|
- A lowercase byte character.
|
|
- A lowercase byte character.
|
|
*/
|
|
*/
|
|
@(private)
|
|
@(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
|
|
Parses a 32-bit floating point number from a string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- s: The input string containing a 32-bit floating point number.
|
|
- 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).
|
|
- 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")
|
|
n, ok = strconv.parse_f32("5678e2")
|
|
fmt.printfln("%.3f %v", n, ok)
|
|
fmt.printfln("%.3f %v", n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
0.000 false
|
|
0.000 false
|
|
567800.000 true
|
|
567800.000 true
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed 32-bit floating point number.
|
|
- 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.
|
|
- 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
|
|
Parses a 64-bit floating point number from a string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- str: The input string containing a 64-bit floating point number.
|
|
- 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).
|
|
- 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")
|
|
n, ok = strconv.parse_f64("5678e2")
|
|
fmt.printfln("%.3f %v", n, ok)
|
|
fmt.printfln("%.3f %v", n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
0.000 false
|
|
0.000 false
|
|
567800.000 true
|
|
567800.000 true
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed 64-bit floating point number.
|
|
- 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.
|
|
- 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
|
|
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.
|
|
- str: The input string containing a 32-bit floating point number.
|
|
|
|
|
|
Example:
|
|
Example:
|
|
@@ -801,14 +801,14 @@ Example:
|
|
n, _, ok = strconv.parse_f32_prefix("5678e2")
|
|
n, _, ok = strconv.parse_f32_prefix("5678e2")
|
|
fmt.printfln("%.3f %v", n, ok)
|
|
fmt.printfln("%.3f %v", n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
0.000 false
|
|
0.000 false
|
|
567800.000 true
|
|
567800.000 true
|
|
-
|
|
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed 32-bit floating point number.
|
|
- value: The parsed 32-bit floating point number.
|
|
- nr: The length of the parsed substring.
|
|
- nr: The length of the parsed substring.
|
|
- ok: A boolean indicating whether the parsing was successful.
|
|
- 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
|
|
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.
|
|
- str: The input string containing a 64-bit floating point number.
|
|
|
|
|
|
Example:
|
|
Example:
|
|
@@ -846,7 +846,7 @@ Output:
|
|
1234.000 true
|
|
1234.000 true
|
|
13.370 true
|
|
13.370 true
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+**Returns**
|
|
- value: The parsed 64-bit floating point number.
|
|
- value: The parsed 64-bit floating point number.
|
|
- nr: The length of the parsed substring.
|
|
- nr: The length of the parsed substring.
|
|
- ok: `false` if a base 10 float could not be found
|
|
- 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
|
|
Parses a 128-bit complex number from a string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- str: The input string containing a 128-bit complex number.
|
|
- 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).
|
|
- 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)
|
|
c, ok = strconv.parse_complex128("5+7i hellope", &n)
|
|
fmt.printfln("%v %i %t", c, n, ok)
|
|
fmt.printfln("%v %i %t", c, n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
3+1i 4 true
|
|
3+1i 4 true
|
|
5+7i 4 false
|
|
5+7i 4 false
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed 128-bit complex number.
|
|
- 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.
|
|
- 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)
|
|
value = complex(real_value, imag_value)
|
|
- return
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
Parses a 64-bit complex number from a string
|
|
Parses a 64-bit complex number from a string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- str: The input string containing a 64-bit complex number.
|
|
- 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).
|
|
- 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)
|
|
c, ok = strconv.parse_complex64("5+7i hellope", &n)
|
|
fmt.printfln("%v %i %t", c, n, ok)
|
|
fmt.printfln("%v %i %t", c, n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
3+1i 4 true
|
|
3+1i 4 true
|
|
5+7i 4 false
|
|
5+7i 4 false
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed 64-bit complex number.
|
|
- 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.
|
|
- 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
|
|
Parses a 32-bit complex number from a string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- str: The input string containing a 32-bit complex number.
|
|
- 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).
|
|
- 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)
|
|
c, ok = strconv.parse_complex32("5+7i hellope", &n)
|
|
fmt.printfln("%v %i %t", c, n, ok)
|
|
fmt.printfln("%v %i %t", c, n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
3+1i 4 true
|
|
3+1i 4 true
|
|
5+7i 4 false
|
|
5+7i 4 false
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed 32-bit complex number.
|
|
- 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.
|
|
- 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
|
|
Parses a 256-bit quaternion from a string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- str: The input string containing a 256-bit quaternion.
|
|
- 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).
|
|
- 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)
|
|
q, ok = strconv.parse_quaternion256("1+2i+3j+4k hellope", &n)
|
|
fmt.printfln("%v %i %t", q, n, ok)
|
|
fmt.printfln("%v %i %t", q, n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
1+2i+3j+4k 10 true
|
|
1+2i+3j+4k 10 true
|
|
1+2i+3j+4k 10 false
|
|
1+2i+3j+4k 10 false
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed 256-bit quaternion.
|
|
- 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.
|
|
- 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
|
|
Parses a 128-bit quaternion from a string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- str: The input string containing a 128-bit quaternion.
|
|
- 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).
|
|
- 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)
|
|
q, ok = strconv.parse_quaternion128("1+2i+3j+4k hellope", &n)
|
|
fmt.printfln("%v %i %t", q, n, ok)
|
|
fmt.printfln("%v %i %t", q, n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
1+2i+3j+4k 10 true
|
|
1+2i+3j+4k 10 true
|
|
1+2i+3j+4k 10 false
|
|
1+2i+3j+4k 10 false
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed 128-bit quaternion.
|
|
- 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.
|
|
- 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
|
|
Parses a 64-bit quaternion from a string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- str: The input string containing a 64-bit quaternion.
|
|
- 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).
|
|
- 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)
|
|
q, ok = strconv.parse_quaternion64("1+2i+3j+4k hellope", &n)
|
|
fmt.printfln("%v %i %t", q, n, ok)
|
|
fmt.printfln("%v %i %t", q, n, ok)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Output:
|
|
Output:
|
|
|
|
|
|
1+2i+3j+4k 10 true
|
|
1+2i+3j+4k 10 true
|
|
1+2i+3j+4k 10 false
|
|
1+2i+3j+4k 10 false
|
|
-
|
|
|
|
-**Returns**
|
|
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
- value: The parsed 64-bit quaternion.
|
|
- 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.
|
|
- ok: `false` if a quaternion could not be found, or if the input string contained more than just the quaternion.
|
|
*/
|
|
*/
|
|
@@ -1450,20 +1450,20 @@ parse_quaternion64 :: proc(str: string, n: ^int = nil) -> (value: quaternion64,
|
|
v, ok = parse_quaternion256(str, n)
|
|
v, ok = parse_quaternion256(str, n)
|
|
return cast(quaternion64)v, ok
|
|
return cast(quaternion64)v, ok
|
|
}
|
|
}
|
|
-/*
|
|
|
|
-Appends a boolean value as a string to the given buffer
|
|
|
|
|
|
+/*
|
|
|
|
+Writes a boolean value as a string to the given buffer
|
|
|
|
|
|
-**Inputs**
|
|
|
|
-- buf: The buffer to append the boolean value to
|
|
|
|
-- b: The boolean value to be appended
|
|
|
|
|
|
+**Inputs**
|
|
|
|
+- buf: The buffer to write the boolean value to
|
|
|
|
+- b: The boolean value to be written
|
|
|
|
|
|
Example:
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
import "core:fmt"
|
|
import "core:strconv"
|
|
import "core:strconv"
|
|
- append_bool_example :: proc() {
|
|
|
|
|
|
+ write_bool_example :: proc() {
|
|
buf: [6]byte
|
|
buf: [6]byte
|
|
- result := strconv.append_bool(buf[:], true)
|
|
|
|
|
|
+ result := strconv.write_bool(buf[:], true)
|
|
fmt.println(result, buf)
|
|
fmt.println(result, buf)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1471,10 +1471,10 @@ Output:
|
|
|
|
|
|
true [116, 114, 117, 101, 0, 0]
|
|
true [116, 114, 117, 101, 0, 0]
|
|
|
|
|
|
-**Returns**
|
|
|
|
-- The resulting string after appending the boolean value
|
|
|
|
|
|
+**Returns**
|
|
|
|
+- The resulting string after writing the boolean value
|
|
*/
|
|
*/
|
|
-append_bool :: proc(buf: []byte, b: bool) -> string {
|
|
|
|
|
|
+write_bool :: proc(buf: []byte, b: bool) -> string {
|
|
n := 0
|
|
n := 0
|
|
if b {
|
|
if b {
|
|
n = copy(buf, "true")
|
|
n = copy(buf, "true")
|
|
@@ -1483,21 +1483,21 @@ append_bool :: proc(buf: []byte, b: bool) -> string {
|
|
}
|
|
}
|
|
return string(buf[:n])
|
|
return string(buf[:n])
|
|
}
|
|
}
|
|
-/*
|
|
|
|
-Appends an unsigned integer value as a string to the given buffer with the specified base
|
|
|
|
|
|
+/*
|
|
|
|
+Writes an unsigned integer value as a string to the given buffer with the specified base
|
|
|
|
|
|
-**Inputs**
|
|
|
|
-- buf: The buffer to append the unsigned integer value to
|
|
|
|
-- u: The unsigned integer value to be appended
|
|
|
|
|
|
+**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
|
|
- base: The base to use for converting the integer value
|
|
|
|
|
|
Example:
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
import "core:fmt"
|
|
import "core:strconv"
|
|
import "core:strconv"
|
|
- append_uint_example :: proc() {
|
|
|
|
|
|
+ write_uint_example :: proc() {
|
|
buf: [4]byte
|
|
buf: [4]byte
|
|
- result := strconv.append_uint(buf[:], 42, 16)
|
|
|
|
|
|
+ result := strconv.write_uint(buf[:], 42, 16)
|
|
fmt.println(result, buf)
|
|
fmt.println(result, buf)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1505,27 +1505,27 @@ Output:
|
|
|
|
|
|
2a [50, 97, 0, 0]
|
|
2a [50, 97, 0, 0]
|
|
|
|
|
|
-**Returns**
|
|
|
|
-- The resulting string after appending the unsigned integer value
|
|
|
|
|
|
+**Returns**
|
|
|
|
+- The resulting string after writing the unsigned integer value
|
|
*/
|
|
*/
|
|
-append_uint :: proc(buf: []byte, u: u64, base: int) -> string {
|
|
|
|
- return append_bits(buf, u, base, false, 8*size_of(uint), digits, nil)
|
|
|
|
|
|
+write_uint :: proc(buf: []byte, u: u64, base: int) -> string {
|
|
|
|
+ return write_bits(buf, u, base, false, 8*size_of(uint), digits, nil)
|
|
}
|
|
}
|
|
-/*
|
|
|
|
-Appends a signed integer value as a string to the given buffer with the specified base
|
|
|
|
|
|
+/*
|
|
|
|
+Writes a signed integer value as a string to the given buffer with the specified base
|
|
|
|
|
|
-**Inputs**
|
|
|
|
-- buf: The buffer to append the signed integer value to
|
|
|
|
-- i: The signed integer value to be appended
|
|
|
|
|
|
+**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
|
|
- base: The base to use for converting the integer value
|
|
|
|
|
|
Example:
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
import "core:fmt"
|
|
import "core:strconv"
|
|
import "core:strconv"
|
|
- append_int_example :: proc() {
|
|
|
|
|
|
+ write_int_example :: proc() {
|
|
buf: [4]byte
|
|
buf: [4]byte
|
|
- result := strconv.append_int(buf[:], -42, 10)
|
|
|
|
|
|
+ result := strconv.write_int(buf[:], -42, 10)
|
|
fmt.println(result, buf)
|
|
fmt.println(result, buf)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1533,23 +1533,23 @@ Output:
|
|
|
|
|
|
-42 [45, 52, 50, 0]
|
|
-42 [45, 52, 50, 0]
|
|
|
|
|
|
-**Returns**
|
|
|
|
-- The resulting string after appending the signed integer value
|
|
|
|
|
|
+**Returns**
|
|
|
|
+- The resulting string after writing the signed integer value
|
|
*/
|
|
*/
|
|
-append_int :: proc(buf: []byte, i: i64, base: int) -> string {
|
|
|
|
- return append_bits(buf, u64(i), base, true, 8*size_of(int), digits, nil)
|
|
|
|
|
|
+write_int :: proc(buf: []byte, i: i64, base: int) -> string {
|
|
|
|
+ return write_bits(buf, u64(i), base, true, 8*size_of(int), digits, nil)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-append_u128 :: proc(buf: []byte, u: u128, base: int) -> string {
|
|
|
|
- return append_bits_128(buf, u, base, false, 8*size_of(uint), digits, nil)
|
|
|
|
|
|
+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
|
|
Converts an integer value to a string and stores it in the given buffer
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- buf: The buffer to store the resulting string
|
|
- buf: The buffer to store the resulting string
|
|
- i: The integer value to be converted
|
|
- i: The integer value to be converted
|
|
|
|
|
|
@@ -1567,16 +1567,16 @@ Output:
|
|
|
|
|
|
42 [52, 50, 0, 0]
|
|
42 [52, 50, 0, 0]
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+**Returns**
|
|
- The resulting string after converting the integer value
|
|
- The resulting string after converting the integer value
|
|
*/
|
|
*/
|
|
itoa :: proc(buf: []byte, i: int) -> string {
|
|
itoa :: proc(buf: []byte, i: int) -> string {
|
|
- return append_int(buf, i64(i), 10)
|
|
|
|
|
|
+ return write_int(buf, i64(i), 10)
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
Converts a string to an integer value
|
|
Converts a string to an integer value
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- s: The string to be converted
|
|
- s: The string to be converted
|
|
|
|
|
|
Example:
|
|
Example:
|
|
@@ -1591,17 +1591,17 @@ Output:
|
|
|
|
|
|
42
|
|
42
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+**Returns**
|
|
- The resulting integer value
|
|
- The resulting integer value
|
|
*/
|
|
*/
|
|
atoi :: proc(s: string) -> int {
|
|
atoi :: proc(s: string) -> int {
|
|
v, _ := parse_int(s)
|
|
v, _ := parse_int(s)
|
|
return v
|
|
return v
|
|
}
|
|
}
|
|
-/*
|
|
|
|
|
|
+/*
|
|
Converts a string to a float64 value
|
|
Converts a string to a float64 value
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- s: The string to be converted
|
|
- s: The string to be converted
|
|
|
|
|
|
Example:
|
|
Example:
|
|
@@ -1616,21 +1616,21 @@ Output:
|
|
|
|
|
|
3.140
|
|
3.140
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+**Returns**
|
|
- The resulting float64 value after converting the string
|
|
- The resulting float64 value after converting the string
|
|
*/
|
|
*/
|
|
atof :: proc(s: string) -> f64 {
|
|
atof :: proc(s: string) -> f64 {
|
|
v, _ := parse_f64(s)
|
|
v, _ := parse_f64(s)
|
|
return v
|
|
return v
|
|
}
|
|
}
|
|
-// Alias to `append_float`
|
|
|
|
-ftoa :: append_float
|
|
|
|
-/*
|
|
|
|
-Appends a float64 value as a string to the given buffer with the specified format and precision
|
|
|
|
-
|
|
|
|
-**Inputs**
|
|
|
|
-- buf: The buffer to append the float64 value to
|
|
|
|
-- f: The float64 value to be appended
|
|
|
|
|
|
+// 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**
|
|
|
|
+- 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
|
|
- fmt: The byte specifying the format to use for the conversion
|
|
- prec: The precision to use for the conversion
|
|
- prec: The precision to use for the conversion
|
|
- bit_size: The size of the float in bits (32 or 64)
|
|
- bit_size: The size of the float in bits (32 or 64)
|
|
@@ -1639,9 +1639,9 @@ Example:
|
|
|
|
|
|
import "core:fmt"
|
|
import "core:fmt"
|
|
import "core:strconv"
|
|
import "core:strconv"
|
|
- append_float_example :: proc() {
|
|
|
|
|
|
+ write_float_example :: proc() {
|
|
buf: [8]byte
|
|
buf: [8]byte
|
|
- result := strconv.append_float(buf[:], 3.14159, 'f', 2, 64)
|
|
|
|
|
|
+ result := strconv.write_float(buf[:], 3.14159, 'f', 2, 64)
|
|
fmt.println(result, buf)
|
|
fmt.println(result, buf)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1649,20 +1649,20 @@ Output:
|
|
|
|
|
|
+3.14 [43, 51, 46, 49, 52, 0, 0, 0]
|
|
+3.14 [43, 51, 46, 49, 52, 0, 0, 0]
|
|
|
|
|
|
-**Returns**
|
|
|
|
-- The resulting string after appending the float
|
|
|
|
|
|
+**Returns**
|
|
|
|
+- The resulting string after writing the float
|
|
*/
|
|
*/
|
|
-append_float :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> string {
|
|
|
|
|
|
+write_float :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> string {
|
|
return string(generic_ftoa(buf, f, fmt, prec, bit_size))
|
|
return string(generic_ftoa(buf, f, fmt, prec, bit_size))
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
-Appends a quoted string representation of the input string to a given byte slice and returns the result as a 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 appended
|
|
|
|
|
|
+**Inputs**
|
|
|
|
+- buf: The byte slice to which the quoted string will be written
|
|
- str: The input string to be quoted
|
|
- str: The input string to be quoted
|
|
|
|
|
|
-!! ISSUE !! NOT EXPECTED -- "\"hello\"" was expected
|
|
|
|
|
|
+!! ISSUE !! NOT EXPECTED -- "\"hello\"" was expected
|
|
|
|
|
|
Example:
|
|
Example:
|
|
|
|
|
|
@@ -1678,8 +1678,8 @@ 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]
|
|
"'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 appending the quoted string representation
|
|
|
|
|
|
+**Returns**
|
|
|
|
+- The resulting string after writing the quoted string representation
|
|
*/
|
|
*/
|
|
quote :: proc(buf: []byte, str: string) -> string {
|
|
quote :: proc(buf: []byte, str: string) -> string {
|
|
write_byte :: proc(buf: []byte, i: ^int, bytes: ..byte) {
|
|
write_byte :: proc(buf: []byte, i: ^int, bytes: ..byte) {
|
|
@@ -1719,10 +1719,10 @@ quote :: proc(buf: []byte, str: string) -> string {
|
|
return string(buf[:i])
|
|
return string(buf[:i])
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
-Appends a quoted rune representation of the input rune to a given byte slice and returns the result as a string
|
|
|
|
|
|
+Writes a quoted rune representation of the input rune to a given byte slice and returns the result as a string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
-- buf: The byte slice to which the quoted rune will be appended
|
|
|
|
|
|
+**Inputs**
|
|
|
|
+- buf: The byte slice to which the quoted rune will be written
|
|
- r: The input rune to be quoted
|
|
- r: The input rune to be quoted
|
|
|
|
|
|
Example:
|
|
Example:
|
|
@@ -1739,8 +1739,8 @@ Output:
|
|
|
|
|
|
'A' [39, 65, 39, 0]
|
|
'A' [39, 65, 39, 0]
|
|
|
|
|
|
-**Returns**
|
|
|
|
-- The resulting string after appending the quoted rune representation
|
|
|
|
|
|
+**Returns**
|
|
|
|
+- The resulting string after writing the quoted rune representation
|
|
*/
|
|
*/
|
|
quote_rune :: proc(buf: []byte, r: rune) -> string {
|
|
quote_rune :: proc(buf: []byte, r: rune) -> string {
|
|
write_byte :: proc(buf: []byte, i: ^int, bytes: ..byte) {
|
|
write_byte :: proc(buf: []byte, i: ^int, bytes: ..byte) {
|
|
@@ -1783,7 +1783,7 @@ quote_rune :: proc(buf: []byte, r: rune) -> string {
|
|
if r < 32 {
|
|
if r < 32 {
|
|
write_string(buf, &i, "\\x")
|
|
write_string(buf, &i, "\\x")
|
|
b: [2]byte
|
|
b: [2]byte
|
|
- s := append_bits(b[:], u64(r), 16, true, 64, digits, nil)
|
|
|
|
|
|
+ s := write_bits(b[:], u64(r), 16, true, 64, digits, nil)
|
|
switch len(s) {
|
|
switch len(s) {
|
|
case 0: write_string(buf, &i, "00")
|
|
case 0: write_string(buf, &i, "00")
|
|
case 1: write_rune(buf, &i, '0')
|
|
case 1: write_rune(buf, &i, '0')
|
|
@@ -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
|
|
Unquotes a single character from the input string, considering the given quote character
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- str: The input string containing the character to unquote
|
|
- str: The input string containing the character to unquote
|
|
- quote: The quote character to consider (e.g., '"')
|
|
- quote: The quote character to consider (e.g., '"')
|
|
|
|
|
|
-Example:
|
|
|
|
|
|
+Example:
|
|
|
|
|
|
import "core:fmt"
|
|
import "core:fmt"
|
|
import "core:strconv"
|
|
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)
|
|
fmt.printf("r: <%v>, multiple_bytes:%v, tail_string:<%s>, success:%v\n",r, multiple_bytes, tail_string, success)
|
|
}
|
|
}
|
|
|
|
|
|
-Output:
|
|
|
|
|
|
+Output:
|
|
|
|
|
|
Source: 'The' raven
|
|
Source: 'The' raven
|
|
r: <'>, multiple_bytes:false, tail_string:<The' raven>, success:true
|
|
r: <'>, multiple_bytes:false, tail_string:<The' raven>, success:true
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+**Returns**
|
|
- r: The unquoted rune
|
|
- r: The unquoted rune
|
|
- multiple_bytes: A boolean indicating if the rune has multiple bytes
|
|
- multiple_bytes: A boolean indicating if the rune has multiple bytes
|
|
- tail_string: The remaining portion of the input string after unquoting the character
|
|
- 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
|
|
Unquotes the input string considering any type of quote character and returns the unquoted string
|
|
|
|
|
|
-**Inputs**
|
|
|
|
|
|
+**Inputs**
|
|
- lit: The input string to unquote
|
|
- lit: The input string to unquote
|
|
- allocator: (default: context.allocator)
|
|
- allocator: (default: context.allocator)
|
|
|
|
|
|
WARNING: This procedure gives unexpected results if the quotes are not the first and last characters.
|
|
WARNING: This procedure gives unexpected results if the quotes are not the first and last characters.
|
|
|
|
|
|
-Example:
|
|
|
|
|
|
+Example:
|
|
|
|
|
|
import "core:fmt"
|
|
import "core:fmt"
|
|
import "core:strconv"
|
|
import "core:strconv"
|
|
@@ -1947,10 +1947,10 @@ Example:
|
|
src="The raven \'Huginn\' is black."
|
|
src="The raven \'Huginn\' is black."
|
|
s, allocated, ok = strconv.unquote_string(src) // Will produce undesireable results
|
|
s, allocated, ok = strconv.unquote_string(src) // Will produce undesireable results
|
|
fmt.println(src)
|
|
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."
|
|
"The raven Huginn is black."
|
|
Unquoted: <The raven Huginn is black.>, alloc:false, ok:true
|
|
Unquoted: <The raven Huginn is black.>, alloc:false, ok:true
|
|
@@ -1961,7 +1961,7 @@ Output:
|
|
The raven 'Huginn' is black.
|
|
The raven 'Huginn' is black.
|
|
Unquoted: <he raven 'Huginn' is black>, alloc:false, ok:true
|
|
Unquoted: <he raven 'Huginn' is black>, alloc:false, ok:true
|
|
|
|
|
|
-**Returns**
|
|
|
|
|
|
+**Returns**
|
|
- res: The resulting unquoted string
|
|
- res: The resulting unquoted string
|
|
- allocated: A boolean indicating if the resulting string was allocated using the provided allocator
|
|
- allocated: A boolean indicating if the resulting string was allocated using the provided allocator
|
|
- success: A boolean indicating whether the unquoting was successful
|
|
- 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
|
|
return s, false, true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
context.allocator = allocator
|
|
context.allocator = allocator
|
|
|
|
|
|
buf_len := 3*len(s) / 2
|
|
buf_len := 3*len(s) / 2
|