MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / parse__escape

Function parse__escape

extern/editline/src/parse.c:138–233  ·  view source on GitHub ↗

parse__escape(): * Parse a string of the form ^ \ \ \U+xxxx and return * the appropriate character or -1 if the escape is not valid */

Source from the content-addressed store, hash-verified

136 * the appropriate character or -1 if the escape is not valid
137 */
138protected int
139parse__escape(const Char **ptr)
140{
141 const Char *p;
142 Int c;
143
144 p = *ptr;
145
146 if (p[1] == 0)
147 return -1;
148
149 if (*p == '\\') {
150 p++;
151 switch (*p) {
152 case 'a':
153 c = '\007'; /* Bell */
154 break;
155 case 'b':
156 c = '\010'; /* Backspace */
157 break;
158 case 't':
159 c = '\011'; /* Horizontal Tab */
160 break;
161 case 'n':
162 c = '\012'; /* New Line */
163 break;
164 case 'v':
165 c = '\013'; /* Vertical Tab */
166 break;
167 case 'f':
168 c = '\014'; /* Form Feed */
169 break;
170 case 'r':
171 c = '\015'; /* Carriage Return */
172 break;
173 case 'e':
174 c = '\033'; /* Escape */
175 break;
176 case 'U': /* Unicode \U+xxxx or \U+xxxxx format */
177 {
178 int i;
179 const Char hex[] = STR("0123456789ABCDEF");
180 const Char *h;
181 ++p;
182 if (*p++ != '+')
183 return -1;
184 c = 0;
185 for (i = 0; i < 5; ++i) {
186 h = Strchr(hex, *p++);
187 if (!h && i < 4)
188 return -1;
189 else if (h)
190 c = (c << 4) | ((int)(h - hex));
191 else
192 --p;
193 }
194 if (c > 0x10FFFF) /* outside valid character range */
195 return -1;

Callers 2

tty_sttyFunction · 0.85
parse__stringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected