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+=(char *str);
|
||||||
|
|
||||||
|
const BString &operator+=(int64_t i);
|
||||||
|
|
||||||
bool operator==(const BString &other);
|
bool operator==(const BString &other);
|
||||||
|
|
||||||
char *data();
|
char *data();
|
||||||
@ -106,7 +108,14 @@ const BString<size> &BString<size>::operator+=(const char *str) {
|
|||||||
|
|
||||||
template<size_t size>
|
template<size_t size>
|
||||||
const BString<size> &BString<size>::operator+=(char *str) {
|
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>
|
template<size_t buffLen>
|
||||||
|
7
deps/ox/src/ox/std/strops.cpp
vendored
7
deps/ox/src/ox/std/strops.cpp
vendored
@ -81,6 +81,7 @@ int ox_atoi(const char *str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *ox_itoa(int64_t v, char *str) {
|
char *ox_itoa(int64_t v, char *str) {
|
||||||
|
if (v) {
|
||||||
auto mod = 1000000000000000000;
|
auto mod = 1000000000000000000;
|
||||||
constexpr auto base = 10;
|
constexpr auto base = 10;
|
||||||
auto it = 0;
|
auto it = 0;
|
||||||
@ -104,5 +105,11 @@ char *ox_itoa(int64_t v, char *str) {
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
str[it] = 0;
|
||||||
|
} else {
|
||||||
|
// 0 is a special case
|
||||||
|
str[0] = '0';
|
||||||
|
str[1] = 0;
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user