Convert Console::printFormat to use kstd format functions

This commit is contained in:
Eryn Wells 2016-03-20 17:07:59 -04:00
parent 2334d80225
commit 17102e7e46

View file

@ -14,8 +14,6 @@
namespace { namespace {
void itoa(int value, char* buffer, int base);
struct Spec { struct Spec {
enum class Size { enum class Size {
Normal, Normal,
@ -107,41 +105,40 @@ Spec::print(kernel::Console& console)
if (type == Type::Int) { if (type == Type::Int) {
switch (size) { switch (size) {
case Size::Normal: case Size::Normal:
itoa(value.d, buf, 10); length = kstd::CString::fromInteger(value.d, buf, 32);
break; break;
case Size::DoubleShort: case Size::DoubleShort:
itoa(value.hhd, buf, 10); length = kstd::CString::fromInteger(value.hhd, buf, 32);
break; break;
case Size::Short: case Size::Short:
itoa(value.hd, buf, 10); length = kstd::CString::fromInteger(value.hd, buf, 32);
break; break;
case Size::Long: case Size::Long:
itoa(value.ld, buf, 10); length = kstd::CString::fromInteger(value.ld, buf, 32);
break; break;
case Size::DoubleLong: case Size::DoubleLong:
itoa(value.lld, buf, 10); length = kstd::CString::fromInteger(value.lld, buf, 32);
break; break;
} }
} else { } else {
switch (size) { switch (size) {
case Size::Normal: case Size::Normal:
kstd::CString::fromUnsignedInteger(value.x, buf, 16, capitalized); length = kstd::CString::fromUnsignedInteger(value.x, buf, 32, 16, capitalized);
break; break;
case Size::DoubleShort: case Size::DoubleShort:
kstd::CString::fromUnsignedInteger(value.hhx, buf, 16, capitalized); length = kstd::CString::fromUnsignedInteger(value.hhx, buf, 32, 16, capitalized);
break; break;
case Size::Short: case Size::Short:
kstd::CString::fromUnsignedInteger(value.hx, buf, 16, capitalized); length = kstd::CString::fromUnsignedInteger(value.hx, buf, 32, 16, capitalized);
break; break;
case Size::Long: case Size::Long:
kstd::CString::fromUnsignedLongInteger(value.lx, buf, 16, capitalized); length = kstd::CString::fromUnsignedInteger(value.lx, buf, 32, 16, capitalized);
break; break;
case Size::DoubleLong: case Size::DoubleLong:
kstd::CString::fromUnsignedLongInteger(value.llx, buf, 16, capitalized); length = kstd::CString::fromUnsignedInteger(value.llx, buf, 32, 16, capitalized);
break; break;
} }
} }
length = kstd::CString::length(buf, 32);
if (width < length) { if (width < length) {
width = length; width = length;
} }
@ -170,43 +167,6 @@ Spec::print(kernel::Console& console)
} }
void
itoa(int value,
char* buffer,
int base)
{
const bool neg = base == 10 && value < 0;
if (neg) {
value *= -1;
}
unsigned int v = (unsigned int)value;
char* p = buffer;
int place;
do {
place = v % base;
v /= base;
*p++ = place < 10 ? place + '0' : (place - 10) + 'a';
} while (v != 0);
if (neg) {
*p++ = '-';
}
*p-- = '\0';
// Reverse the string.
char* t = buffer;
char c;
while (p > t) {
c = *p;
*p-- = *t;
*t++ = c;
}
}
inline bool inline bool
is_size(char c) is_size(char c)
{ {