Browse Source

short C names deprecated (itoa, ftoa), C reimplementations of atoi and atof deprecated as parse_int() and parse_f64() are preferable

samwega 1 week ago
parent
commit
01bbd981ad
2 changed files with 30 additions and 54 deletions
  1. 24 0
      core/strconv/deprecated.odin
  2. 6 54
      core/strconv/strconv.odin

+ 24 - 0
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))
+}

+ 6 - 54
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**