diff options
author | Frederich Munch <colsebas@hotmail.com> | 2017-07-13 16:11:08 +0000 |
---|---|---|
committer | Frederich Munch <colsebas@hotmail.com> | 2017-07-13 16:11:08 +0000 |
commit | d6657666e994cb95d89449c440095f9daa402c20 (patch) | |
tree | eec8883aa1a7827195ac02903881bd5047317ee6 /lib/Support | |
parent | 74479e8cb31bdb7e2073b0c9e1e7e3f275c75fdb (diff) |
Support: Add llvm::center_justify.
Summary: Completes the set.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: ruiu, llvm-commits
Differential Revision: https://reviews.llvm.org/D35278
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307922 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-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; } |