MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / processStringEscapes

Method processStringEscapes

erpcgen/src/ErpcLexer.cpp:71–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71int ErpcLexer::processStringEscapes(const char *in, char *out)
72{
73 int count = 0;
74 while (*in)
75 {
76 switch (*in)
77 {
78 case '\\':
79 {
80 // start of an escape sequence
81 char c = *++in;
82 switch (c)
83 {
84 case 0: // end of the string, bail
85 {
86 break;
87 }
88 case 'x':
89 {
90 // start of a hex char escape sequence
91
92 // read high and low nibbles, checking for end of string
93 char hi = *++in;
94 if (hi == 0)
95 {
96 break;
97 }
98 char lo = *++in;
99 if (lo == 0)
100 {
101 break;
102 }
103
104 if (isHexDigit(hi) && isHexDigit(lo))
105 {
106 *out++ = (hexCharToInt(hi) << 4) | hexCharToInt(lo);
107 count++;
108 }
109 else
110 {
111 // not hex digits, the \x must have wanted an 'x' char
112 *out++ = 'x';
113 *out++ = hi;
114 *out++ = lo;
115 count += 3;
116 }
117 break;
118 }
119 case 'n':
120 {
121 *out++ = '\n';
122 count++;
123 break;
124 }
125 case 't':
126 {
127 *out++ = '\t';
128 count++;

Callers

nothing calls this directly

Calls 2

isHexDigitFunction · 0.85
hexCharToIntFunction · 0.85

Tested by

no test coverage detected