diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-07-19 07:02:10 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-07-19 07:02:10 +0000 | 
| commit | 93c91e39b29142dec1d03a30df9f6e757f56c193 (patch) | |
| tree | 33a9b014a327e64450b3c9ed46d8c5bdb78ad345 /lib/Support/raw_ostream.cpp | |
| parent | ca089b24d48ef6fa8da2d0bb8c25bb802c4a95c0 (diff) | |
Notes
Diffstat (limited to 'lib/Support/raw_ostream.cpp')
| -rw-r--r-- | lib/Support/raw_ostream.cpp | 29 | 
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 9480cd46d28f..dd58eccee957 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -326,13 +326,30 @@ raw_ostream &raw_ostream::operator<<(const formatv_object_base &Obj) {  }  raw_ostream &raw_ostream::operator<<(const FormattedString &FS) { -  unsigned Len = FS.Str.size();  -  int PadAmount = FS.Width - Len; -  if (FS.RightJustify && (PadAmount > 0)) -    this->indent(PadAmount); -  this->operator<<(FS.Str); -  if (!FS.RightJustify && (PadAmount > 0)) +  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"); +  }    return *this;  }  | 
