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