MCPcopy Create free account
hub / github.com/catboost/catboost / EscapeC

Function EscapeC

library/cpp/yson/writer.cpp:45–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43 const size_t ESCAPE_C_BUFFER_SIZE = 4;
44
45 inline size_t EscapeC(unsigned char c, char next, char r[ESCAPE_C_BUFFER_SIZE]) {
46 // (1) Printable characters go as-is, except backslash and double quote.
47 // (2) Characters \r, \n, \t and \0 ... \7 replaced by their simple escape characters (if possible).
48 // (3) Otherwise, character is encoded using hexadecimal escape sequence (if possible), or octal.
49 if (c == '\"') {
50 r[0] = '\\';
51 r[1] = '\"';
52 return 2;
53 } else if (c == '\\') {
54 r[0] = '\\';
55 r[1] = '\\';
56 return 2;
57 } else if (IsPrintable(c)) {
58 r[0] = c;
59 return 1;
60 } else if (c == '\r') {
61 r[0] = '\\';
62 r[1] = 'r';
63 return 2;
64 } else if (c == '\n') {
65 r[0] = '\\';
66 r[1] = 'n';
67 return 2;
68 } else if (c == '\t') {
69 r[0] = '\\';
70 r[1] = 't';
71 return 2;
72 } else if (c < 8 && !IsOctDigit(next)) {
73 r[0] = '\\';
74 r[1] = OctDigit(c);
75 return 2;
76 } else if (!IsHexDigit(next)) {
77 r[0] = '\\';
78 r[1] = 'x';
79 r[2] = HexDigit((c & 0xF0) >> 4);
80 r[3] = HexDigit((c & 0x0F) >> 0);
81 return 4;
82 } else {
83 r[0] = '\\';
84 r[1] = OctDigit((c & 0700) >> 6);
85 r[2] = OctDigit((c & 0070) >> 3);
86 r[3] = OctDigit((c & 0007) >> 0);
87 return 4;
88 }
89 }
90
91 void EscapeC(const char* str, size_t len, IOutputStream& output) {
92 char buffer[ESCAPE_C_BUFFER_SIZE];

Callers 7

WriteStringScalarMethod · 0.70
cow_string.hFile · 0.50
CharMethod · 0.50
Y_UNIT_TESTFunction · 0.50
TESTFunction · 0.50
Y_UNIT_TESTFunction · 0.50

Calls 6

IsPrintableFunction · 0.70
IsOctDigitFunction · 0.70
OctDigitFunction · 0.70
IsHexDigitFunction · 0.70
HexDigitFunction · 0.70
WriteMethod · 0.45

Tested by

no test coverage detected