23 #ifndef WPIUTIL_WPI_FORMAT_H
24 #define WPIUTIL_WPI_FORMAT_H
26 #include "wpi/ArrayRef.h"
27 #include "wpi/STLExtras.h"
28 #include "wpi/StringRef.h"
46 virtual int snprint(
char *Buffer,
unsigned BufferSize)
const = 0;
54 unsigned print(
char *Buffer,
unsigned BufferSize)
const {
55 assert(BufferSize &&
"Invalid buffer size!");
58 int N =
snprint(Buffer, BufferSize);
62 return BufferSize * 2;
66 if (
unsigned(N) >= BufferSize)
81 template <
typename Arg,
typename... Args>
83 static_assert(std::is_scalar<Arg>::value,
84 "format can't be used with non fundamental / non pointer type");
89 template <
typename... Ts>
91 std::tuple<Ts...> Vals;
93 template <std::size_t... Is>
94 int snprint_tuple(
char *Buffer,
unsigned BufferSize,
97 return _snprintf(Buffer, BufferSize, Fmt, std::get<Is>(Vals)...);
100 #pragma GCC diagnostic push
101 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
103 return snprintf(Buffer, BufferSize, Fmt, std::get<Is>(Vals)...);
105 #pragma GCC diagnostic pop
116 int snprint(
char *Buffer,
unsigned BufferSize)
const override {
130 template <
typename... Ts>
138 enum Justification { JustifyNone, JustifyLeft, JustifyRight, JustifyCenter };
140 : Str(S), Width(W), Justify(J) {}
145 Justification Justify;
183 : HexValue(HV), DecValue(DV), Width(W), Hex(H), Upper(U),
194 bool Upper =
false) {
195 assert(Width <= 18 &&
"hex width must be <= 18");
207 bool Upper =
false) {
208 assert(Width <= 16 &&
"hex width must be <= 16");
227 uint32_t IndentLevel;
229 uint8_t ByteGroupSize;
236 uint32_t NPL, uint8_t BGS,
bool U,
bool A)
237 : Bytes(B), FirstByteOffset(O), IndentLevel(IL), NumPerLine(NPL),
238 ByteGroupSize(BGS), Upper(U), ASCII(A) {
240 if (ByteGroupSize > NumPerLine)
241 ByteGroupSize = NumPerLine;
247 uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4,
248 uint32_t IndentLevel = 0,
bool Upper =
false) {
249 return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine,
250 ByteGroupSize, Upper,
false);
253 inline FormattedBytes
254 format_bytes_with_ascii(ArrayRef<uint8_t> Bytes,
255 Optional<uint64_t> FirstByteOffset = None,
256 uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4,
257 uint32_t IndentLevel = 0,
bool Upper =
false) {
258 return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine,
259 ByteGroupSize, Upper,
true);
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
FormattedString center_justify(StringRef Str, unsigned Width)
center_justify - add spaces before and after string so total output is Width characters.
Definition: Format.h:166
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition: Format.h:193
FormattedString right_justify(StringRef Str, unsigned Width)
right_justify - add spaces before string so total output is Width characters.
Definition: Format.h:159
Alias for the common case of a sequence of size_ts.
Definition: STLExtras.h:407
namespace to hold default to_json function
Definition: SmallString.h:21
Creates a compile-time integer sequence for a parameter pack.
Definition: STLExtras.h:409
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:131
FormattedNumber format_decimal(int64_t N, unsigned Width)
format_decimal - Output N as a right justified, fixed-width decimal.
Definition: Format.h:218
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
Definition: Format.h:206
FormattedString left_justify(StringRef Str, unsigned Width)
left_justify - append spaces after string so total output is Width characters.
Definition: Format.h:152