diff options
| author | samwega <alexanderglavan@gmail.com> | 2025-10-03 20:54:18 +0300 |
|---|---|---|
| committer | samwega <alexanderglavan@gmail.com> | 2025-10-03 20:54:18 +0300 |
| commit | 01bbd981adccc63e9934a2ad7760985d029d6807 (patch) | |
| tree | ddea43f24b37704c1bcef77c0218f2c9e3b6b52a /core/strconv | |
| parent | 54805c600e26b17f4efad974bf5fecde3fa90a8a (diff) | |
short C names deprecated (itoa, ftoa), C reimplementations of atoi and atof deprecated as parse_int() and parse_f64() are preferable
Diffstat (limited to 'core/strconv')
| -rw-r--r-- | core/strconv/deprecated.odin | 24 | ||||
| -rw-r--r-- | core/strconv/strconv.odin | 60 |
2 files changed, 30 insertions, 54 deletions
diff --git a/core/strconv/deprecated.odin b/core/strconv/deprecated.odin index 883822e4b..20cd2642e 100644 --- a/core/strconv/deprecated.odin +++ b/core/strconv/deprecated.odin @@ -36,3 +36,27 @@ append_u128 :: proc(buf: []byte, u: u128, base: int) -> string { append_float :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> string { return write_float(buf, f, fmt, prec, bit_size) } + +// 2025-10-03 Deprecated C short names and implementations + +@(deprecated="Use int_to_string instead") +itoa :: proc(buf: []byte, i: int) -> string { + return write_int(buf, i64(i), 10) +} + +@(deprecated="Use strconv.parse_int() instead") +atoi :: proc(s: string) -> int { + v, _ := parse_int(s) + return v +} + +@(deprecated="Use parse_f64() instead") +atof :: proc(s: string) -> f64 { + v, _ := parse_f64(s) + return v +} + +@(deprecated="Use write_float instead") +ftoa :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> string { + return string(generic_ftoa(buf, f, fmt, prec, bit_size)) +}
\ No newline at end of file diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin index 652da1adb..e7de67c42 100644 --- a/core/strconv/strconv.odin +++ b/core/strconv/strconv.odin @@ -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 - -**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")) - } +`ftoa` C name deprecated, use `int_to_string` instead (same procedure) -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** |