File indexing completed on 2026-05-10 08:44:30
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_SUPPORT_FORMATCOMMON_H
0010 #define LLVM_SUPPORT_FORMATCOMMON_H
0011
0012 #include "llvm/ADT/SmallString.h"
0013 #include "llvm/Support/FormatVariadicDetails.h"
0014 #include "llvm/Support/raw_ostream.h"
0015
0016 namespace llvm {
0017 enum class AlignStyle { Left, Center, Right };
0018
0019
0020
0021 struct FmtAlign {
0022 support::detail::format_adapter &Adapter;
0023 AlignStyle Where;
0024 unsigned Width;
0025 char Fill;
0026
0027 FmtAlign(support::detail::format_adapter &Adapter, AlignStyle Where,
0028 unsigned Width, char Fill = ' ')
0029 : Adapter(Adapter), Where(Where), Width(Width), Fill(Fill) {}
0030
0031 void format(raw_ostream &S, StringRef Options) {
0032
0033
0034
0035
0036
0037 if (Width == 0) {
0038 Adapter.format(S, Options);
0039 return;
0040 }
0041 SmallString<64> Item;
0042 raw_svector_ostream Stream(Item);
0043
0044 Adapter.format(Stream, Options);
0045 if (Width <= Item.size()) {
0046 S << Item;
0047 return;
0048 }
0049
0050 unsigned PadAmount = Width - static_cast<unsigned>(Item.size());
0051 switch (Where) {
0052 case AlignStyle::Left:
0053 S << Item;
0054 fill(S, PadAmount);
0055 break;
0056 case AlignStyle::Center: {
0057 unsigned X = PadAmount / 2;
0058 fill(S, X);
0059 S << Item;
0060 fill(S, PadAmount - X);
0061 break;
0062 }
0063 default:
0064 fill(S, PadAmount);
0065 S << Item;
0066 break;
0067 }
0068 }
0069
0070 private:
0071 void fill(llvm::raw_ostream &S, unsigned Count) {
0072 for (unsigned I = 0; I < Count; ++I)
0073 S << Fill;
0074 }
0075 };
0076 }
0077
0078 #endif