mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
short C names deprecated (itoa, ftoa), C reimplementations of atoi and atof deprecated as parse_int() and parse_f64() are preferable
This commit is contained in:
@@ -1547,6 +1547,8 @@ write_u128 :: proc(buf: []byte, u: u128, base: int) -> string {
|
||||
}
|
||||
|
||||
/*
|
||||
`itoa` C name deprecated, use `int_to_string` instead (same procedure)
|
||||
|
||||
Converts an integer value to a string and stores it in the given buffer
|
||||
|
||||
**Inputs**
|
||||
@@ -1557,9 +1559,9 @@ Example:
|
||||
|
||||
import "core:fmt"
|
||||
import "core:strconv"
|
||||
itoa_example :: proc() {
|
||||
int_to_string_example :: proc() {
|
||||
buf: [4]byte
|
||||
result := strconv.itoa(buf[:], 42)
|
||||
result := strconv.int_to_string(buf[:], 42)
|
||||
fmt.println(result, buf) // "42"
|
||||
}
|
||||
|
||||
@@ -1570,62 +1572,12 @@ Output:
|
||||
**Returns**
|
||||
- The resulting string after converting the integer value
|
||||
*/
|
||||
itoa :: proc(buf: []byte, i: int) -> string {
|
||||
int_to_string :: proc(buf: []byte, i: int) -> string {
|
||||
return write_int(buf, i64(i), 10)
|
||||
}
|
||||
/*
|
||||
Converts a string to an integer value
|
||||
`ftoa` C name deprecated, use `int_to_string` instead (same procedure)
|
||||
|
||||
**Inputs**
|
||||
- s: The string to be converted
|
||||
|
||||
Example:
|
||||
|
||||
import "core:fmt"
|
||||
import "core:strconv"
|
||||
atoi_example :: proc() {
|
||||
fmt.println(strconv.atoi("42"))
|
||||
}
|
||||
|
||||
Output:
|
||||
|
||||
42
|
||||
|
||||
**Returns**
|
||||
- The resulting integer value
|
||||
*/
|
||||
atoi :: proc(s: string) -> int {
|
||||
v, _ := parse_int(s)
|
||||
return v
|
||||
}
|
||||
/*
|
||||
Converts a string to a float64 value
|
||||
|
||||
**Inputs**
|
||||
- s: The string to be converted
|
||||
|
||||
Example:
|
||||
|
||||
import "core:fmt"
|
||||
import "core:strconv"
|
||||
atof_example :: proc() {
|
||||
fmt.printfln("%.3f", strconv.atof("3.14"))
|
||||
}
|
||||
|
||||
Output:
|
||||
|
||||
3.140
|
||||
|
||||
**Returns**
|
||||
- The resulting float64 value after converting the string
|
||||
*/
|
||||
atof :: proc(s: string) -> f64 {
|
||||
v, _ := parse_f64(s)
|
||||
return v
|
||||
}
|
||||
// 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**
|
||||
|
||||
Reference in New Issue
Block a user