raw_ostream: Simplify code a bit. NFCI.

This commit is contained in:
Benjamin Kramer 2020-04-26 14:05:55 +02:00
parent a3982491db
commit 609c2873e7
1 changed files with 21 additions and 24 deletions

View File

@ -343,36 +343,33 @@ raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) {
} }
raw_ostream &raw_ostream::operator<<(const formatv_object_base &Obj) { raw_ostream &raw_ostream::operator<<(const formatv_object_base &Obj) {
SmallString<128> S;
Obj.format(*this); Obj.format(*this);
return *this; return *this;
} }
raw_ostream &raw_ostream::operator<<(const FormattedString &FS) { raw_ostream &raw_ostream::operator<<(const FormattedString &FS) {
if (FS.Str.size() >= FS.Width || FS.Justify == FormattedString::JustifyNone) { unsigned LeftIndent = 0;
this->operator<<(FS.Str); unsigned RightIndent = 0;
return *this; const ssize_t Difference = FS.Width - FS.Str.size();
} if (Difference > 0) {
const size_t Difference = FS.Width - FS.Str.size();
switch (FS.Justify) { switch (FS.Justify) {
case FormattedString::JustifyNone:
break;
case FormattedString::JustifyLeft: case FormattedString::JustifyLeft:
this->operator<<(FS.Str); RightIndent = Difference;
this->indent(Difference);
break; break;
case FormattedString::JustifyRight: case FormattedString::JustifyRight:
this->indent(Difference); LeftIndent = Difference;
this->operator<<(FS.Str);
break; break;
case FormattedString::JustifyCenter: { case FormattedString::JustifyCenter:
int PadAmount = Difference / 2; LeftIndent = Difference / 2;
this->indent(PadAmount); RightIndent = Difference - LeftIndent;
this->operator<<(FS.Str);
this->indent(Difference - PadAmount);
break; break;
} }
default:
llvm_unreachable("Bad Justification");
} }
indent(LeftIndent);
(*this) << FS.Str;
indent(RightIndent);
return *this; return *this;
} }