@@ -259,21 +259,38 @@ class FormattedNumber {
259
259
unsigned Width;
260
260
bool Hex;
261
261
bool Upper;
262
+ bool HexPrefix;
262
263
friend class raw_ostream ;
263
264
public:
264
- FormattedNumber (uint64_t HV, int64_t DV, unsigned W, bool H, bool U)
265
- : HexValue(HV), DecValue(DV), Width(W), Hex(H), Upper(U) { }
265
+ FormattedNumber (uint64_t HV, int64_t DV, unsigned W, bool H, bool U,
266
+ bool Prefix)
267
+ : HexValue(HV), DecValue(DV), Width(W), Hex(H), Upper(U),
268
+ HexPrefix (Prefix) {}
266
269
};
267
270
268
271
// / format_hex - Output \p N as a fixed width hexadecimal. If number will not
269
272
// / fit in width, full number is still printed. Examples:
270
- // / OS << format_hex(255, 4) => 0xff
271
- // / OS << format_hex(255, 4, true) => 0xFF
272
- // / OS << format_hex(255, 6) => 0x00ff
273
- // / OS << format_hex(255, 2) => 0xff
274
- inline FormattedNumber format_hex (uint64_t N, unsigned Width, bool Upper=false ) {
273
+ // / OS << format_hex(255, 4) => 0xff
274
+ // / OS << format_hex(255, 4, true) => 0xFF
275
+ // / OS << format_hex(255, 6) => 0x00ff
276
+ // / OS << format_hex(255, 2) => 0xff
277
+ inline FormattedNumber format_hex (uint64_t N, unsigned Width,
278
+ bool Upper = false ) {
275
279
assert (Width <= 18 && " hex width must be <= 18" );
276
- return FormattedNumber (N, 0 , Width, true , Upper);
280
+ return FormattedNumber (N, 0 , Width, true , Upper, true );
281
+ }
282
+
283
+ // / format_hex_no_prefix - Output \p N as a fixed width hexadecimal. Does not
284
+ // / prepend '0x' to the outputted string. If number will not fit in width,
285
+ // / full number is still printed. Examples:
286
+ // / OS << format_hex_no_prefix(255, 4) => ff
287
+ // / OS << format_hex_no_prefix(255, 4, true) => FF
288
+ // / OS << format_hex_no_prefix(255, 6) => 00ff
289
+ // / OS << format_hex_no_prefix(255, 2) => ff
290
+ inline FormattedNumber format_hex_no_prefix (uint64_t N, unsigned Width,
291
+ bool Upper = false ) {
292
+ assert (Width <= 18 && " hex width must be <= 18" );
293
+ return FormattedNumber (N, 0 , Width, true , Upper, false );
277
294
}
278
295
279
296
// / format_decimal - Output \p N as a right justified, fixed-width decimal. If
@@ -283,7 +300,7 @@ inline FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
283
300
// / OS << format_decimal(-1, 3) => " -1"
284
301
// / OS << format_decimal(12345, 3) => "12345"
285
302
inline FormattedNumber format_decimal (int64_t N, unsigned Width) {
286
- return FormattedNumber (0 , N, Width, false , false );
303
+ return FormattedNumber (0 , N, Width, false , false , false );
287
304
}
288
305
289
306
0 commit comments