MCPcopy Create free account
hub / github.com/ceph/ceph / pretty_binary_string

Function pretty_binary_string

src/common/pretty_binary.h:9–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8template<typename S>
9static std::string pretty_binary_string(const S& bin)
10{
11 std::string pretty;
12 if (bin.empty())
13 return pretty;
14 pretty.reserve(bin.length() * 3);
15 auto printable = [](unsigned char c) -> bool {
16 return (c >= 32) && (c <= 126);
17 };
18 auto append_hex = [&](unsigned char c) {
19 static const char hex[16] = {'0', '1', '2', '3',
20 '4', '5', '6', '7',
21 '8', '9', 'A', 'B',
22 'C', 'D', 'E', 'F'};
23 pretty.push_back(hex[c / 16]);
24 pretty.push_back(hex[c % 16]);
25 };
26 // prologue
27 bool strmode = printable(bin[0]);
28 if (strmode) {
29 pretty.push_back('\'');
30 } else {
31 pretty.push_back('0');
32 pretty.push_back('x');
33 }
34 for (size_t i = 0; i < bin.length(); ++i) {
35 // change mode from hex to str if following 3 characters are printable
36 if (strmode) {
37 if (!printable(bin[i])) {
38 pretty.push_back('\'');
39 pretty.push_back('0');
40 pretty.push_back('x');
41 strmode = false;
42 }
43 } else {
44 if (i + 2 < bin.length() &&
45 printable(bin[i]) &&
46 printable(bin[i + 1]) &&
47 printable(bin[i + 2])) {
48 pretty.push_back('\'');
49 strmode = true;
50 }
51 }
52 if (strmode) {
53 if (bin[i] == '\'')
54 pretty.push_back('\'');
55 pretty.push_back(bin[i]);
56 } else {
57 append_hex(bin[i]);
58 }
59 }
60 // epilog
61 if (strmode) {
62 pretty.push_back('\'');
63 }
64 return pretty;
65}
66

Callers 15

build_size_histogramMethod · 0.85
dumpMethod · 0.85
rm_range_keysMethod · 0.85
reshardMethod · 0.85
util_divide_key_rangeMethod · 0.85
get_object_keyFunction · 0.85
reshard_decisionMethod · 0.85
load_shared_blobMethod · 0.85
get_onodeMethod · 0.85
_open_collectionsMethod · 0.85
_open_statfsMethod · 0.85

Calls 4

emptyMethod · 0.45
reserveMethod · 0.45
lengthMethod · 0.45
push_backMethod · 0.45

Tested by 2

TESTFunction · 0.68
TEST_PFunction · 0.68