1 //===- FormatAdapters.h - Formatters for common LLVM types -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_SUPPORT_FORMATCOMMON_H
11 #define LLVM_SUPPORT_FORMATCOMMON_H
13 #include "llvm/ADT/SmallString.h"
14 #include "llvm/Support/FormatVariadicDetails.h"
15 #include "llvm/Support/raw_ostream.h"
18 enum class AlignStyle { Left, Center, Right };
21 detail::format_wrapper &Wrapper;
25 FmtAlign(detail::format_wrapper &Wrapper, AlignStyle Where, size_t Amount)
26 : Wrapper(Wrapper), Where(Where), Amount(Amount) {}
28 void format(raw_ostream &S, StringRef Options) {
29 // If we don't need to align, we can format straight into the underlying
30 // stream. Otherwise we have to go through an intermediate stream first
31 // in order to calculate how long the output is so we can align it.
32 // TODO: Make the format method return the number of bytes written, that
33 // way we can also skip the intermediate stream for left-aligned output.
35 Wrapper.format(S, Options);
39 raw_svector_ostream Stream(Item);
41 Wrapper.format(Stream, Options);
42 if (Amount <= Item.size()) {
47 size_t PadAmount = Amount - Item.size();
49 case AlignStyle::Left:
53 case AlignStyle::Center: {
54 size_t X = PadAmount / 2;
57 S.indent(PadAmount - X);