forked from OSchip/llvm-project
raw_ostream: Simplify code a bit. NFCI.
This commit is contained in:
parent
a3982491db
commit
609c2873e7
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue