1 | #include <Formats/verbosePrintString.h> |
---|---|
2 | #include <Common/hex.h> |
3 | #include <IO/Operators.h> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | void verbosePrintString(const char * begin, const char * end, WriteBuffer & out) |
10 | { |
11 | if (end == begin) |
12 | { |
13 | out << "<EMPTY>"; |
14 | return; |
15 | } |
16 | |
17 | out << "\""; |
18 | |
19 | for (auto pos = begin; pos < end; ++pos) |
20 | { |
21 | switch (*pos) |
22 | { |
23 | case '\0': |
24 | out << "<ASCII NUL>"; |
25 | break; |
26 | case '\b': |
27 | out << "<BACKSPACE>"; |
28 | break; |
29 | case '\f': |
30 | out << "<FORM FEED>"; |
31 | break; |
32 | case '\n': |
33 | out << "<LINE FEED>"; |
34 | break; |
35 | case '\r': |
36 | out << "<CARRIAGE RETURN>"; |
37 | break; |
38 | case '\t': |
39 | out << "<TAB>"; |
40 | break; |
41 | case '\\': |
42 | out << "<BACKSLASH>"; |
43 | break; |
44 | case '"': |
45 | out << "<DOUBLE QUOTE>"; |
46 | break; |
47 | case '\'': |
48 | out << "<SINGLE QUOTE>"; |
49 | break; |
50 | |
51 | default: |
52 | { |
53 | if (static_cast<unsigned char>(*pos) < 32) /// ASCII control characters |
54 | out << "<0x"<< hexDigitUppercase(*pos / 16) << hexDigitUppercase(*pos % 16) << ">"; |
55 | else |
56 | out << *pos; |
57 | } |
58 | } |
59 | } |
60 | |
61 | out << "\""; |
62 | } |
63 | |
64 | } |
65 |