| 66 | // Moved from string_functions namespace in str.cpp for better organization |
| 67 | |
| 68 | int itoa(i32 value, char *sp, int radix) { |
| 69 | char tmp[16]; // be careful with the length of the buffer |
| 70 | char *tp = tmp; |
| 71 | int i; |
| 72 | u32 v; |
| 73 | |
| 74 | int sign = (radix == 10 && value < 0); |
| 75 | if (sign) |
| 76 | v = -static_cast<u32>(value); |
| 77 | else |
| 78 | v = static_cast<u32>(value); |
| 79 | |
| 80 | while (v || tp == tmp) { |
| 81 | i = v % radix; |
| 82 | v = radix ? v / radix : 0; |
| 83 | if (i < 10) |
| 84 | *tp++ = i + '0'; |
| 85 | else |
| 86 | *tp++ = i + 'a' - 10; |
| 87 | } |
| 88 | |
| 89 | int len = tp - tmp; |
| 90 | |
| 91 | if (sign) { |
| 92 | *sp++ = '-'; |
| 93 | len++; |
| 94 | } |
| 95 | |
| 96 | while (tp > tmp) |
| 97 | *sp++ = *--tp; |
| 98 | |
| 99 | *sp = '\0'; // Null-terminate the string |
| 100 | return len; |
| 101 | } |
| 102 | |
| 103 | int itoa64(i64 value, char *sp, int radix) { |
| 104 | char tmp[32]; // Buffer for 64-bit integer (max 65 chars for base 2 + sign) |
no outgoing calls
no test coverage detected