]> git.ipfire.org Git - thirdparty/squid.git/blob - src/base/IoManip.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / base / IoManip.cc
1 /*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10 #include "base/IoManip.h"
11 #include "debug/Stream.h"
12
13 #include <algorithm>
14
15 void
16 PrintHex(std::ostream &os, const char * const data, const size_t n)
17 {
18 if (!n)
19 return;
20 assert(data);
21
22 const auto savedFill = os.fill('0');
23 const auto savedFlags = os.flags(); // std::ios_base::fmtflags
24 os << std::hex;
25 std::for_each(data, data + n,
26 [&os](const char &c) { os << std::setw(2) << static_cast<uint8_t>(c); });
27 os.flags(savedFlags);
28 os.fill(savedFill);
29 }
30