Simplify HexDumpSlice.
GitOrigin-RevId: 4350523696d5d20092db4006e2c88324c1e3a636
This commit is contained in:
parent
a80e0621e4
commit
d78a1d0a33
@ -46,21 +46,18 @@ struct HexDumpSlice {
|
|||||||
|
|
||||||
template <std::size_t align>
|
template <std::size_t align>
|
||||||
StringBuilder &operator<<(StringBuilder &builder, const HexDumpSlice<align> &dump) {
|
StringBuilder &operator<<(StringBuilder &builder, const HexDumpSlice<align> &dump) {
|
||||||
std::size_t size = dump.slice.size();
|
const auto str = dump.slice;
|
||||||
const unsigned char *ptr = dump.slice.ubegin();
|
const auto size = str.size();
|
||||||
|
|
||||||
builder << '\n';
|
builder << '\n';
|
||||||
|
|
||||||
const std::size_t part = size % align;
|
const std::size_t first_part_size = size % align;
|
||||||
if (part) {
|
if (first_part_size) {
|
||||||
builder << HexDumpSlice<1>{Slice(ptr, part)} << '\n';
|
builder << HexDumpSlice<1>{str.substr(0, first_part_size)} << '\n';
|
||||||
}
|
}
|
||||||
size -= part;
|
|
||||||
ptr += part;
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < size; i += align) {
|
for (std::size_t i = first_part_size; i < size; i += align) {
|
||||||
builder << HexDumpSize<align>{ptr};
|
builder << HexDumpSize<align>{str.ubegin() + i};
|
||||||
ptr += align;
|
|
||||||
|
|
||||||
if (((i / align) & 15) == 15 || i + align >= size) {
|
if (((i / align) & 15) == 15 || i + align >= size) {
|
||||||
builder << '\n';
|
builder << '\n';
|
||||||
|
Reference in New Issue
Block a user