Fix issues with int to string conversion in ox string operations
This commit is contained in:
parent
13a394e07f
commit
ccf308d022
11
deps/ox/src/ox/std/string.hpp
vendored
11
deps/ox/src/ox/std/string.hpp
vendored
@ -35,6 +35,8 @@ class BString {
|
||||
|
||||
const BString &operator+=(char *str);
|
||||
|
||||
const BString &operator+=(int64_t i);
|
||||
|
||||
bool operator==(const BString &other);
|
||||
|
||||
char *data();
|
||||
@ -106,7 +108,14 @@ const BString<size> &BString<size>::operator+=(const char *str) {
|
||||
|
||||
template<size_t size>
|
||||
const BString<size> &BString<size>::operator+=(char *str) {
|
||||
return *this = (const char*) str;
|
||||
return *this += (const char*) str;
|
||||
}
|
||||
|
||||
template<size_t size>
|
||||
const BString<size> &BString<size>::operator+=(int64_t i) {
|
||||
char str[65];
|
||||
ox_itoa(i, str);
|
||||
return this->operator+=(str);
|
||||
}
|
||||
|
||||
template<size_t buffLen>
|
||||
|
47
deps/ox/src/ox/std/strops.cpp
vendored
47
deps/ox/src/ox/std/strops.cpp
vendored
@ -81,28 +81,35 @@ int ox_atoi(const char *str) {
|
||||
}
|
||||
|
||||
char *ox_itoa(int64_t v, char *str) {
|
||||
auto mod = 1000000000000000000;
|
||||
constexpr auto base = 10;
|
||||
auto it = 0;
|
||||
if (v < 0) {
|
||||
str[it] = '-';
|
||||
it++;
|
||||
}
|
||||
while (mod) {
|
||||
auto digit = v / mod;
|
||||
v %= mod;
|
||||
mod /= base;
|
||||
if (it or digit) {
|
||||
int start;
|
||||
if (digit < 10) {
|
||||
start = '0';
|
||||
} else {
|
||||
start = 'a';
|
||||
digit -= 10;
|
||||
}
|
||||
str[it] = start + digit;
|
||||
if (v) {
|
||||
auto mod = 1000000000000000000;
|
||||
constexpr auto base = 10;
|
||||
auto it = 0;
|
||||
if (v < 0) {
|
||||
str[it] = '-';
|
||||
it++;
|
||||
}
|
||||
while (mod) {
|
||||
auto digit = v / mod;
|
||||
v %= mod;
|
||||
mod /= base;
|
||||
if (it or digit) {
|
||||
int start;
|
||||
if (digit < 10) {
|
||||
start = '0';
|
||||
} else {
|
||||
start = 'a';
|
||||
digit -= 10;
|
||||
}
|
||||
str[it] = start + digit;
|
||||
it++;
|
||||
}
|
||||
}
|
||||
str[it] = 0;
|
||||
} else {
|
||||
// 0 is a special case
|
||||
str[0] = '0';
|
||||
str[1] = 0;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user