llvm.org GIT mirror llvm / 48fbf5c
[Support] Improve flexibility of binary blob formatter. This makes it possible to indent a binary blob by a certain number of bytes, and also makes some things more idiomatic. Finally, it integrates this binary blob formatter into ScopedPrinter which used to have its own implementation of this algorithm. Differential Revision: https://reviews.llvm.org/D26477 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286495 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 3 years ago
5 changed file(s) with 169 addition(s) and 176 deletion(s). Raw diff Collapse all Expand all
202202 return FormattedNumber(0, N, Width, false, false, false);
203203 }
204204
205 class FormattedHexBytes {
206 llvm::ArrayRef Bytes;
207 // Display offsets for each line if FirstByteOffset has a value.
208 llvm::Optional FirstByteOffset;
205 class FormattedBytes {
206 ArrayRef Bytes;
207
208 // If not None, display offsets for each line relative to starting value.
209 Optional FirstByteOffset;
210 uint32_t IndentLevel; // Number of characters to indent each line.
209211 uint32_t NumPerLine; // Number of bytes to show per line.
210212 uint8_t ByteGroupSize; // How many hex bytes are grouped without spaces
211213 bool Upper; // Show offset and hex bytes as upper case.
213215 friend class raw_ostream;
214216
215217 public:
216 FormattedHexBytes(llvm::ArrayRef B, llvm::Optional O,
217 uint32_t NPL, uint8_t BGS, bool U, bool A)
218 : Bytes(B), FirstByteOffset(O), NumPerLine(NPL), ByteGroupSize(BGS),
219 Upper(U), ASCII(A) {}
220 };
221
222 inline FormattedHexBytes format_hex_bytes(
223 llvm::ArrayRef Bytes,
224 llvm::Optional FirstByteOffset = llvm::Optional(),
225 uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4) {
226 return FormattedHexBytes(Bytes, FirstByteOffset, NumPerLine, ByteGroupSize,
227 false /*Upper*/, false /*ASCII*/);
228 }
229
230 inline FormattedHexBytes format_hex_bytes_with_ascii(
231 llvm::ArrayRef Bytes,
232 llvm::Optional FirstByteOffset = llvm::Optional(),
233 uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4) {
234 return FormattedHexBytes(Bytes, FirstByteOffset, NumPerLine, ByteGroupSize,
235 false /*Upper*/, true /*ASCII*/);
218 FormattedBytes(ArrayRef B, uint32_t IL, Optional O,
219 uint32_t NPL, uint8_t BGS, bool U, bool A)
220 : Bytes(B), IndentLevel(IL), FirstByteOffset(O), NumPerLine(NPL),
221 ByteGroupSize(BGS), Upper(U), ASCII(A) {
222
223 if (ByteGroupSize > NumPerLine)
224 ByteGroupSize = NumPerLine;
225 }
226 };
227
228 inline FormattedBytes
229 format_bytes(ArrayRef Bytes, Optional FirstByteOffset = None,
230 uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4,
231 uint32_t IndentLevel = 0, bool Upper = false) {
232 return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine,
233 ByteGroupSize, Upper, false);
234 }
235
236 inline FormattedBytes
237 format_bytes_with_ascii(ArrayRef Bytes,
238 Optional FirstByteOffset = None,
239 uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4,
240 uint32_t IndentLevel = 0, bool Upper = false) {
241 return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine,
242 ByteGroupSize, Upper, true);
236243 }
237244
238245 } // end namespace llvm
2222 class format_object_base;
2323 class FormattedString;
2424 class FormattedNumber;
25 class FormattedHexBytes;
25 class FormattedBytes;
2626 template class SmallVectorImpl;
2727
2828 namespace sys {
222222 // Formatted output, see the formatHex() function in Support/Format.h.
223223 raw_ostream &operator<<(const FormattedNumber &);
224224
225 // Formatted output, see the formatHex() function in Support/Format.h.
226 raw_ostream &operator<<(const FormattedHexBytes &);
225 // Formatted output, see the format_bytes() function in Support/Format.h.
226 raw_ostream &operator<<(const FormattedBytes &);
227227
228228 /// indent - Insert 'NumSpaces' spaces.
229229 raw_ostream &indent(unsigned NumSpaces);
2626
2727 if (Block) {
2828 startLine() << Label;
29 if (Str.size() > 0)
29 if (!Str.empty())
3030 OS << ": " << Str;
3131 OS << " (\n";
32 for (size_t addr = 0, end = Data.size(); addr < end; addr += 16) {
33 startLine() << format(" %04" PRIX64 ": ", uint64_t(addr));
34 // Dump line of hex.
35 for (size_t i = 0; i < 16; ++i) {
36 if (i != 0 && i % 4 == 0)
37 OS << ' ';
38 if (addr + i < end)
39 OS << hexdigit((Data[addr + i] >> 4) & 0xF, false)
40 << hexdigit(Data[addr + i] & 0xF, false);
41 else
42 OS << " ";
43 }
44 // Print ascii.
45 OS << " |";
46 for (std::size_t i = 0; i < 16 && addr + i < end; ++i) {
47 if (std::isprint(Data[addr + i] & 0xFF))
48 OS << Data[addr + i];
49 else
50 OS << ".";
51 }
52 OS << "|\n";
53 }
54
32 if (!Data.empty())
33 OS << format_bytes_with_ascii(Data, 0, 16, 4, (IndentLevel + 1) * 2, true)
34 << "\n";
5535 startLine() << ")\n";
5636 } else {
5737 startLine() << Label << ":";
58 if (Str.size() > 0)
38 if (!Str.empty())
5939 OS << " " << Str;
60 OS << " (";
61 for (size_t i = 0; i < Data.size(); ++i) {
62 if (i > 0)
63 OS << " ";
64
65 OS << format("%02X", static_cast(Data[i]));
66 }
67 OS << ")\n";
40 OS << " (" << format_bytes(Data, None, Data.size(), 1, 0, true) << ")\n";
6841 }
6942 }
7043
351351 return *this;
352352 }
353353
354 raw_ostream &raw_ostream::operator<<(const FormattedHexBytes &FB) {
354 raw_ostream &raw_ostream::operator<<(const FormattedBytes &FB) {
355 if (FB.Bytes.empty())
356 return *this;
357
355358 size_t LineIndex = 0;
356 const size_t Size = FB.Bytes.size();
357 HexPrintStyle OffsetStyle =
358 FB.Upper ? HexPrintStyle::PrefixUpper : HexPrintStyle::PrefixLower;
359 HexPrintStyle ByteStyle =
360 FB.Upper ? HexPrintStyle::Upper : HexPrintStyle::Lower;
361 while (LineIndex < Size) {
359 auto Bytes = FB.Bytes;
360 const size_t Size = Bytes.size();
361 HexPrintStyle HPS = FB.Upper ? HexPrintStyle::Upper : HexPrintStyle::Lower;
362 uint64_t OffsetWidth = 0;
363 if (FB.FirstByteOffset.hasValue()) {
364 // Figure out how many nibbles are needed to print the largest offset
365 // represented by this data set, so that we can align the offset field
366 // to the right width.
367 size_t Lines = Size / FB.NumPerLine;
368 uint64_t MaxOffset = *FB.FirstByteOffset + Lines * FB.NumPerLine;
369 unsigned Power = 0;
370 if (MaxOffset > 0)
371 Power = llvm::Log2_64_Ceil(MaxOffset);
372 OffsetWidth = std::max(4ULL, llvm::alignTo(Power, 4) / 4);
373 }
374
375 // The width of a block of data including all spaces for group separators.
376 unsigned NumByteGroups =
377 alignTo(FB.NumPerLine, FB.ByteGroupSize) / FB.ByteGroupSize;
378 unsigned BlockCharWidth = FB.NumPerLine * 2 + NumByteGroups - 1;
379
380 while (!Bytes.empty()) {
381 indent(FB.IndentLevel);
382
362383 if (FB.FirstByteOffset.hasValue()) {
363384 uint64_t Offset = FB.FirstByteOffset.getValue();
364 llvm::write_hex(*this, Offset + LineIndex, OffsetStyle,
365 sizeof(Offset) * 2 + 2);
385 llvm::write_hex(*this, Offset + LineIndex, HPS, OffsetWidth);
366386 *this << ": ";
367387 }
368 // Print the hex bytes for this line
369 uint32_t I = 0;
370 for (I = 0; I < FB.NumPerLine; ++I) {
371 size_t Index = LineIndex + I;
372 if (Index >= Size)
373 break;
374 if (I && (I % FB.ByteGroupSize) == 0)
388
389 auto Line = Bytes.take_front(FB.NumPerLine);
390
391 size_t CharsPrinted = 0;
392 // Print the hex bytes for this line in groups
393 for (size_t I = 0; I < Line.size(); ++I, CharsPrinted += 2) {
394 if (I && (I % FB.ByteGroupSize) == 0) {
395 ++CharsPrinted;
375396 *this << " ";
376 llvm::write_hex(*this, FB.Bytes[Index], ByteStyle, 2);
377 }
378 uint32_t BytesDisplayed = I;
397 }
398 llvm::write_hex(*this, Line[I], HPS, 2);
399 }
400
379401 if (FB.ASCII) {
380402 // Print any spaces needed for any bytes that we didn't print on this
381403 // line so that the ASCII bytes are correctly aligned.
382 for (; I < FB.NumPerLine; ++I) {
383 if (I && (I % FB.ByteGroupSize) == 0)
384 indent(3);
385 else
386 indent(2);
387 }
388 *this << " |";
404 assert(BlockCharWidth >= CharsPrinted);
405 indent(BlockCharWidth - CharsPrinted + 2);
406 *this << "|";
407
389408 // Print the ASCII char values for each byte on this line
390 for (I = 0; I < FB.NumPerLine; ++I) {
391 size_t Index = LineIndex + I;
392 if (Index >= Size)
393 break;
394 char ch = (char)FB.Bytes[Index];
395 if (isprint(ch))
396 *this << ch;
409 for (uint8_t Byte : Line) {
410 if (isprint(Byte))
411 *this << static_cast(Byte);
397412 else
398413 *this << '.';
399414 }
400415 *this << '|';
401416 }
402 LineIndex += BytesDisplayed;
417
418 Bytes = Bytes.drop_front(Line.size());
419 LineIndex += Line.size();
403420 if (LineIndex < Size)
404421 *this << '\n';
405422 }
180180 printToString(format_decimal(INT64_MIN, 21), 21));
181181 }
182182
183 std::string
184 format_hex_bytes(const void *P, size_t N,
185 llvm::Optional Offset = llvm::Optional(),
186 uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4) {
183 static std::string formatted_bytes_str(ArrayRef Bytes,
184 llvm::Optional Offset = None,
185 uint32_t NumPerLine = 16,
186 uint8_t ByteGroupSize = 4) {
187187 std::string S;
188 if (P && N) {
189 llvm::raw_string_ostream Str(S);
190 Str << llvm::format_hex_bytes(
191 llvm::ArrayRef(static_cast(P), N), Offset,
192 NumPerLine, ByteGroupSize);
193 Str.flush();
194 }
188 raw_string_ostream Str(S);
189 Str << format_bytes(Bytes, Offset, NumPerLine, ByteGroupSize);
190 Str.flush();
195191 return S;
196192 }
197193
198 std::string format_hex_bytes_with_ascii(
199 const void *P, size_t N,
200 llvm::Optional Offset = llvm::Optional(),
201 uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4) {
194 static std::string format_bytes_with_ascii_str(ArrayRef Bytes,
195 Optional Offset = None,
196 uint32_t NumPerLine = 16,
197 uint8_t ByteGroupSize = 4) {
202198 std::string S;
203 if (P && N) {
204 llvm::raw_string_ostream Str(S);
205 Str << llvm::format_hex_bytes_with_ascii(
206 llvm::ArrayRef(static_cast(P), N), Offset,
207 NumPerLine, ByteGroupSize);
208 Str.flush();
209 }
199 raw_string_ostream Str(S);
200 Str << format_bytes_with_ascii(Bytes, Offset, NumPerLine, ByteGroupSize);
201 Str.flush();
210202 return S;
211203 }
212204
213205 TEST(raw_ostreamTest, FormattedHexBytes) {
214 char b[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
215 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
216 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
217 // Test raw bytes
218 const llvm::Optional InvalidOffset;
206 std::vector Buf = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
207 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
208 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0',
209 '1', '2', '3', '4', '5', '6', '7', '8', '9'};
210 ArrayRef B(Buf);
211
219212 // Test invalid input.
220 EXPECT_EQ("", format_hex_bytes(nullptr, 0));
221 EXPECT_EQ("", format_hex_bytes(b, 0));
222 EXPECT_EQ("", format_hex_bytes(nullptr, 16));
213 EXPECT_EQ("", formatted_bytes_str(ArrayRef()));
214 EXPECT_EQ("", format_bytes_with_ascii_str(ArrayRef()));
223215 //----------------------------------------------------------------------
224216 // Test hex byte output with the default 4 byte groups
225217 //----------------------------------------------------------------------
226 EXPECT_EQ("61", format_hex_bytes(b, 1));
227 EXPECT_EQ("61626364 65", format_hex_bytes(b, 5));
218 EXPECT_EQ("61", formatted_bytes_str(B.take_front()));
219 EXPECT_EQ("61626364 65", formatted_bytes_str(B.take_front(5)));
228220 // Test that 16 bytes get written to a line correctly.
229 EXPECT_EQ("61626364 65666768 696a6b6c 6d6e6f70", format_hex_bytes(b, 16));
221 EXPECT_EQ("61626364 65666768 696a6b6c 6d6e6f70",
222 formatted_bytes_str(B.take_front(16)));
230223 // Test raw bytes with default 16 bytes per line wrapping.
231 EXPECT_EQ("61626364 65666768 696a6b6c 6d6e6f70\n71", format_hex_bytes(b, 17));
224 EXPECT_EQ("61626364 65666768 696a6b6c 6d6e6f70\n71",
225 formatted_bytes_str(B.take_front(17)));
232226 // Test raw bytes with 1 bytes per line wrapping.
233 EXPECT_EQ("61\n62\n63\n64\n65\n66", format_hex_bytes(b, 6, InvalidOffset, 1));
227 EXPECT_EQ("61\n62\n63\n64\n65\n66",
228 formatted_bytes_str(B.take_front(6), None, 1));
234229 // Test raw bytes with 7 bytes per line wrapping.
235230 EXPECT_EQ("61626364 656667\n68696a6b 6c6d6e\n6f7071",
236 format_hex_bytes(b, 17, InvalidOffset, 7));
231 formatted_bytes_str(B.take_front(17), None, 7));
237232 // Test raw bytes with 8 bytes per line wrapping.
238233 EXPECT_EQ("61626364 65666768\n696a6b6c 6d6e6f70\n71",
239 format_hex_bytes(b, 17, InvalidOffset, 8));
234 formatted_bytes_str(B.take_front(17), None, 8));
240235 //----------------------------------------------------------------------
241236 // Test hex byte output with the 1 byte groups
242237 //----------------------------------------------------------------------
243 EXPECT_EQ("61 62 63 64 65", format_hex_bytes(b, 5, InvalidOffset, 16, 1));
238 EXPECT_EQ("61 62 63 64 65",
239 formatted_bytes_str(B.take_front(5), None, 16, 1));
244240 // Test that 16 bytes get written to a line correctly.
245241 EXPECT_EQ("61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70",
246 format_hex_bytes(b, 16, InvalidOffset, 16, 1));
242 formatted_bytes_str(B.take_front(16), None, 16, 1));
247243 // Test raw bytes with default 16 bytes per line wrapping.
248244 EXPECT_EQ("61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70\n71",
249 format_hex_bytes(b, 17, InvalidOffset, 16, 1));
245 formatted_bytes_str(B.take_front(17), None, 16, 1));
250246 // Test raw bytes with 7 bytes per line wrapping.
251247 EXPECT_EQ("61 62 63 64 65 66 67\n68 69 6a 6b 6c 6d 6e\n6f 70 71",
252 format_hex_bytes(b, 17, InvalidOffset, 7, 1));
248 formatted_bytes_str(B.take_front(17), None, 7, 1));
253249 // Test raw bytes with 8 bytes per line wrapping.
254250 EXPECT_EQ("61 62 63 64 65 66 67 68\n69 6a 6b 6c 6d 6e 6f 70\n71",
255 format_hex_bytes(b, 17, InvalidOffset, 8, 1));
251 formatted_bytes_str(B.take_front(17), None, 8, 1));
256252
257253 //----------------------------------------------------------------------
258254 // Test hex byte output with the 2 byte groups
259255 //----------------------------------------------------------------------
260 EXPECT_EQ("6162 6364 65", format_hex_bytes(b, 5, InvalidOffset, 16, 2));
256 EXPECT_EQ("6162 6364 65", formatted_bytes_str(B.take_front(5), None, 16, 2));
261257 // Test that 16 bytes get written to a line correctly.
262258 EXPECT_EQ("6162 6364 6566 6768 696a 6b6c 6d6e 6f70",
263 format_hex_bytes(b, 16, InvalidOffset, 16, 2));
259 formatted_bytes_str(B.take_front(16), None, 16, 2));
264260 // Test raw bytes with default 16 bytes per line wrapping.
265261 EXPECT_EQ("6162 6364 6566 6768 696a 6b6c 6d6e 6f70\n71",
266 format_hex_bytes(b, 17, InvalidOffset, 16, 2));
262 formatted_bytes_str(B.take_front(17), None, 16, 2));
267263 // Test raw bytes with 7 bytes per line wrapping.
268264 EXPECT_EQ("6162 6364 6566 67\n6869 6a6b 6c6d 6e\n6f70 71",
269 format_hex_bytes(b, 17, InvalidOffset, 7, 2));
265 formatted_bytes_str(B.take_front(17), None, 7, 2));
270266 // Test raw bytes with 8 bytes per line wrapping.
271267 EXPECT_EQ("6162 6364 6566 6768\n696a 6b6c 6d6e 6f70\n71",
272 format_hex_bytes(b, 17, InvalidOffset, 8, 2));
268 formatted_bytes_str(B.take_front(17), None, 8, 2));
273269
274270 //----------------------------------------------------------------------
275271 // Test hex bytes with offset with the default 4 byte groups.
276272 //----------------------------------------------------------------------
277 EXPECT_EQ("0x0000000000000000: 61", format_hex_bytes(b, 1, 0x0));
278 EXPECT_EQ("0x0000000000001000: 61", format_hex_bytes(b, 1, 0x1000));
279 EXPECT_EQ("0x0000000000001000: 61\n0x0000000000001001: 62",
280 format_hex_bytes(b, 2, 0x1000, 1));
273 EXPECT_EQ("0000: 61", formatted_bytes_str(B.take_front(), 0x0));
274 EXPECT_EQ("1000: 61", formatted_bytes_str(B.take_front(), 0x1000));
275 EXPECT_EQ("1000: 61\n1001: 62",
276 formatted_bytes_str(B.take_front(2), 0x1000, 1));
281277 //----------------------------------------------------------------------
282278 // Test hex bytes with ASCII with the default 4 byte groups.
283279 //----------------------------------------------------------------------
284280 EXPECT_EQ("61626364 65666768 696a6b6c 6d6e6f70 |abcdefghijklmnop|",
285 format_hex_bytes_with_ascii(b, 16));
281 format_bytes_with_ascii_str(B.take_front(16)));
286282 EXPECT_EQ("61626364 65666768 |abcdefgh|\n"
287283 "696a6b6c 6d6e6f70 |ijklmnop|",
288 format_hex_bytes_with_ascii(b, 16, InvalidOffset, 8));
284 format_bytes_with_ascii_str(B.take_front(16), None, 8));
289285 EXPECT_EQ("61626364 65666768 |abcdefgh|\n696a6b6c |ijkl|",
290 format_hex_bytes_with_ascii(b, 12, InvalidOffset, 8));
291 char unprintable[] = {'a', '\x1e', 'b', '\x1f'};
286 format_bytes_with_ascii_str(B.take_front(12), None, 8));
287 std::vector Unprintable = {'a', '\x1e', 'b', '\x1f'};
292288 // Make sure the ASCII is still lined up correctly when fewer bytes than 16
293289 // bytes per line are available. The ASCII should still be aligned as if 16
294290 // bytes of hex might be displayed.
295291 EXPECT_EQ("611e621f |a.b.|",
296 format_hex_bytes_with_ascii(unprintable, 4));
292 format_bytes_with_ascii_str(Unprintable));
297293 //----------------------------------------------------------------------
298294 // Test hex bytes with ASCII with offsets with the default 4 byte groups.
299295 //----------------------------------------------------------------------
300 EXPECT_EQ("0x0000000000000000: 61626364 65666768 "
296 EXPECT_EQ("0000: 61626364 65666768 "
301297 "696a6b6c 6d6e6f70 |abcdefghijklmnop|",
302 format_hex_bytes_with_ascii(b, 16, 0));
303 EXPECT_EQ("0x0000000000000000: 61626364 65666768 |abcdefgh|\n"
304 "0x0000000000000008: 696a6b6c 6d6e6f70 |ijklmnop|",
305 format_hex_bytes_with_ascii(b, 16, 0, 8));
306 EXPECT_EQ("0x0000000000000000: 61626364 656667 |abcdefg|\n"
307 "0x0000000000000007: 68696a6b 6c |hijkl|",
308 format_hex_bytes_with_ascii(b, 12, 0, 7));
298 format_bytes_with_ascii_str(B.take_front(16), 0));
299 EXPECT_EQ("0000: 61626364 65666768 |abcdefgh|\n"
300 "0008: 696a6b6c 6d6e6f70 |ijklmnop|",
301 format_bytes_with_ascii_str(B.take_front(16), 0, 8));
302 EXPECT_EQ("0000: 61626364 656667 |abcdefg|\n"
303 "0007: 68696a6b 6c |hijkl|",
304 format_bytes_with_ascii_str(B.take_front(12), 0, 7));
309305
310306 //----------------------------------------------------------------------
311307 // Test hex bytes with ASCII with offsets with the default 2 byte groups.
312308 //----------------------------------------------------------------------
313 EXPECT_EQ("0x0000000000000000: 6162 6364 6566 6768 "
309 EXPECT_EQ("0000: 6162 6364 6566 6768 "
314310 "696a 6b6c 6d6e 6f70 |abcdefghijklmnop|",
315 format_hex_bytes_with_ascii(b, 16, 0, 16, 2));
316 EXPECT_EQ("0x0000000000000000: 6162 6364 6566 6768 |abcdefgh|\n"
317 "0x0000000000000008: 696a 6b6c 6d6e 6f70 |ijklmnop|",
318 format_hex_bytes_with_ascii(b, 16, 0, 8, 2));
319 EXPECT_EQ("0x0000000000000000: 6162 6364 6566 67 |abcdefg|\n"
320 "0x0000000000000007: 6869 6a6b 6c |hijkl|",
321 format_hex_bytes_with_ascii(b, 12, 0, 7, 2));
311 format_bytes_with_ascii_str(B.take_front(16), 0, 16, 2));
312 EXPECT_EQ("0000: 6162 6364 6566 6768 |abcdefgh|\n"
313 "0008: 696a 6b6c 6d6e 6f70 |ijklmnop|",
314 format_bytes_with_ascii_str(B.take_front(16), 0, 8, 2));
315 EXPECT_EQ("0000: 6162 6364 6566 67 |abcdefg|\n"
316 "0007: 6869 6a6b 6c |hijkl|",
317 format_bytes_with_ascii_str(B.take_front(12), 0, 7, 2));
322318
323319 //----------------------------------------------------------------------
324320 // Test hex bytes with ASCII with offsets with the default 1 byte groups.
325321 //----------------------------------------------------------------------
326 EXPECT_EQ("0x0000000000000000: 61 62 63 64 65 66 67 68 "
322 EXPECT_EQ("0000: 61 62 63 64 65 66 67 68 "
327323 "69 6a 6b 6c 6d 6e 6f 70 |abcdefghijklmnop|",
328 format_hex_bytes_with_ascii(b, 16, 0, 16, 1));
329 EXPECT_EQ("0x0000000000000000: 61 62 63 64 65 66 67 68 |abcdefgh|\n"
330 "0x0000000000000008: 69 6a 6b 6c 6d 6e 6f 70 |ijklmnop|",
331 format_hex_bytes_with_ascii(b, 16, 0, 8, 1));
332 EXPECT_EQ("0x0000000000000000: 61 62 63 64 65 66 67 |abcdefg|\n"
333 "0x0000000000000007: 68 69 6a 6b 6c |hijkl|",
334 format_hex_bytes_with_ascii(b, 12, 0, 7, 1));
335 }
336 }
324 format_bytes_with_ascii_str(B.take_front(16), 0, 16, 1));
325 EXPECT_EQ("0000: 61 62 63 64 65 66 67 68 |abcdefgh|\n"
326 "0008: 69 6a 6b 6c 6d 6e 6f 70 |ijklmnop|",
327 format_bytes_with_ascii_str(B.take_front(16), 0, 8, 1));
328 EXPECT_EQ("0000: 61 62 63 64 65 66 67 |abcdefg|\n"
329 "0007: 68 69 6a 6b 6c |hijkl|",
330 format_bytes_with_ascii_str(B.take_front(12), 0, 7, 1));
331 }
332 }