Adds numeric prefixes to console printing.
This commit is contained in:
parent
b3b0ac66fb
commit
7ae608fc3c
2 changed files with 22 additions and 0 deletions
|
@ -59,6 +59,11 @@ private:
|
|||
* Moves the hardware caret.
|
||||
*/
|
||||
void updateCaret();
|
||||
|
||||
/**
|
||||
* Prints the prefix for a given numeric base.
|
||||
*/
|
||||
void printNumericPrefix(uint32_t base);
|
||||
public:
|
||||
Console(Screen *screen);
|
||||
|
||||
|
|
|
@ -168,6 +168,7 @@ template<>
|
|||
Console & Console::operator << <uint32_t>(const NumericFormat<uint32_t> & fmt)
|
||||
{
|
||||
char buffer[13];
|
||||
this->printNumericPrefix(fmt.base);
|
||||
size_t len = Numeric::toString(buffer, sizeof(buffer), fmt.value, fmt.base);
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
this->put(buffer[i]);
|
||||
|
@ -179,6 +180,7 @@ template<>
|
|||
Console & Console::operator << <int32_t>(const NumericFormat<int32_t> & fmt)
|
||||
{
|
||||
char buffer[13];
|
||||
this->printNumericPrefix(fmt.base);
|
||||
size_t len = Numeric::toString(buffer, sizeof(buffer), fmt.value, fmt.base);
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
this->put(buffer[i]);
|
||||
|
@ -190,6 +192,7 @@ template<>
|
|||
Console & Console::operator << <uint64_t>(const NumericFormat<uint64_t> & fmt)
|
||||
{
|
||||
char buffer[13];
|
||||
this->printNumericPrefix(fmt.base);
|
||||
size_t len = Numeric::toString(buffer, sizeof(buffer), fmt.value, fmt.base);
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
this->put(buffer[i]);
|
||||
|
@ -201,9 +204,23 @@ template<>
|
|||
Console & Console::operator << <int64_t>(const NumericFormat<int64_t> & fmt)
|
||||
{
|
||||
char buffer[13];
|
||||
this->printNumericPrefix(fmt.base);
|
||||
size_t len = Numeric::toString(buffer, sizeof(buffer), fmt.value, fmt.base);
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
this->put(buffer[i]);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Console::printNumericPrefix(uint32_t base)
|
||||
{
|
||||
switch(base) {
|
||||
case 2: *this << "0b"; break;
|
||||
case 8: *this << "0o"; break;
|
||||
case 10: return;
|
||||
case 16: *this << "0x"; break;
|
||||
default:
|
||||
*this << "[" << base << "]x";
|
||||
break;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue