Fix issues with int to string conversion in ox string operations

This commit is contained in:
Gary Talent 2018-03-14 00:20:04 -05:00
parent 13a394e07f
commit ccf308d022
2 changed files with 37 additions and 21 deletions

View File

@ -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>

View File

@ -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;
} }