263 return print_token(symbol); |
263 return print_token(symbol); |
264 } |
264 } |
265 |
265 |
266 void *visit(single_byte_character_string_c *symbol) { |
266 void *visit(single_byte_character_string_c *symbol) { |
267 std::string str = ""; |
267 std::string str = ""; |
268 |
268 unsigned int count = 0; |
269 str += '"'; |
269 str += '"'; |
270 /* we ignore the first and last bytes, they will be the character ' */ |
270 /* we ignore the first and last bytes, they will be the character ' */ |
271 for (unsigned int i = 1; i < strlen(symbol->value) - 1; i++) { |
271 for (unsigned int i = 1; i < strlen(symbol->value) - 1; i++) { |
272 char c = symbol->value[i]; |
272 char c = symbol->value[i]; |
273 if ((c == '\\') || (c == '"')) |
273 if ((c == '\\') || (c == '"')) |
274 {str += '\\'; str += c; continue;} |
274 {str += '\\'; str += c; count ++; continue;} |
275 if (c != '$') |
275 if (c != '$') |
276 {str += c; continue;} |
276 {str += c; count++; continue;} |
277 /* this should be safe, since the code has passed the syntax parser!! */ |
277 /* this should be safe, since the code has passed the syntax parser!! */ |
278 c = symbol->value[++i]; |
278 c = symbol->value[++i]; |
279 switch (c) { |
279 switch (c) { |
280 case '$': |
280 case '$': |
281 case '\'': |
281 case '\'': |
282 {str += c; continue;} |
282 {str += c; count++; continue;} |
283 case 'L': |
283 case 'L': |
284 case 'l': |
284 case 'l': |
285 {str += "\x0A"; /* LF */; continue;} |
285 {str += "\x0A"; /* LF */; count++; continue;} |
286 case 'N': |
286 case 'N': |
287 case 'n': |
287 case 'n': |
288 {str += "\\x0A"; /* NL */; continue;} |
288 {str += "\\x0A"; /* NL */; count++; continue;} |
289 case 'P': |
289 case 'P': |
290 case 'p': |
290 case 'p': |
291 {str += "\\f"; /* FF */; continue;} |
291 {str += "\\f"; /* FF */; count++; continue;} |
292 case 'R': |
292 case 'R': |
293 case 'r': |
293 case 'r': |
294 {str += "\\r"; /* CR */; continue;} |
294 {str += "\\r"; /* CR */; count++; continue;} |
295 case 'T': |
295 case 'T': |
296 case 't': |
296 case 't': |
297 {str += "\\t"; /* tab */; continue;} |
297 {str += "\\t"; /* tab */; count++; continue;} |
298 default: { |
298 default: { |
299 if (isxdigit(c)) { |
299 if (isxdigit(c)) { |
300 /* this should be safe, since the code has passed the syntax parser!! */ |
300 /* this should be safe, since the code has passed the syntax parser!! */ |
301 char c2 = symbol->value[++i]; |
301 char c2 = symbol->value[++i]; |
302 if (isxdigit(c2)) { |
302 if (isxdigit(c2)) { |
303 str += '\\'; str += 'x'; str += c; str += c2; |
303 str += '\\'; str += 'x'; str += c; str += c2; |
304 continue; |
304 count++; continue; |
305 } |
305 } |
306 } |
306 } |
307 } |
307 } |
308 /* otherwise we have an invalid string!! */ |
308 /* otherwise we have an invalid string!! */ |
309 /* This should not have got through the syntax parser! */ |
309 /* This should not have got through the syntax parser! */ |
310 ERROR; |
310 ERROR; |
311 } /* switch() */ |
311 } /* switch() */ |
312 } /* for() */ |
312 } /* for() */ |
313 |
313 |
314 str += '"'; |
314 str += '"'; |
315 |
315 s4o.print("(STRING){"); |
|
316 s4o.print_integer(count); |
|
317 s4o.print(","); |
316 s4o.print(str); |
318 s4o.print(str); |
|
319 s4o.print("}"); |
317 return NULL; |
320 return NULL; |
318 } |
321 } |
319 |
322 |
320 |
323 |
321 /***************************/ |
324 /***************************/ |