1

clean outstream

This commit is contained in:
2022-07-23 22:46:03 +02:00
parent 226a247043
commit ddad13defa
2 changed files with 49 additions and 72 deletions

View File

@ -22,47 +22,48 @@
#include "lib/OutStream.h"
// NOTE: I added this, fixed width printing
void OutStream::put(char c) {
if (this->fill_width == 0) {
if (fill_width == 0) {
StringBuffer::put(c);
} else if (this->fill_used == this->fill_width - 1) {
} else if (fill_used == fill_width - 1) {
// This indicates that content has been cut
StringBuffer::put('@');
this->fill_use_char();
} else if (this->fill_used == this->fill_width) {
fill_use_char();
} else if (fill_used == fill_width) {
// do nothing
} else {
StringBuffer::put(c);
this->fill_use_char();
fill_use_char();
}
}
void OutStream::fill_finalize() {
if (this->fill_width == 0 || this->fill_used == this->fill_width) {
if (fill_width == 0 || fill_used == fill_width) {
// do nothing
} else if (this->fill_used > this->fill_width) {
} else if (fill_used > fill_width) {
// should never happen
} else {
for (unsigned char i = 0; i < this->fill_width - this->fill_used; ++i) {
StringBuffer::put(this->fill_char);
for (unsigned char i = 0; i < fill_width - fill_used; ++i) {
StringBuffer::put(fill_char);
}
}
this->fill_used = 0;
fill_used = 0;
}
void OutStream::fill_use_char() {
if (this->fill_width == 0) {
if (fill_width == 0) {
return;
}
this->fill_used++;
fill_used++;
}
void OutStream::flush() {
// TODO: Should not be reset like this
// Flushing resets fixed width
this->base = 10;
this->fill_char = ' ';
this->fill_width = 0;
this->fill_used = 0;
base = 10;
fill_char = ' ';
fill_width = 0;
fill_used = 0;
}
//