Provides functionality to interpret C escape sequences in strings.
This file contains functions to interpret C-style escape sequences such as
(newline), \t (tab), and octal specifications like \ddd.
- Copyright
- (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
- (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
- License
- This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
- Author
- M. Borland, C. Saunders, R. Soliday
Definition in file interpret_escapes.c.
void interpret_escapes |
( |
char * | s | ) |
|
Interpret C escape sequences in a string.
This function processes the input string and replaces C-style escape sequences (such as
for newline, \t for tab, and octal sequences like \ddd) with their corresponding characters.
- Parameters
-
s | Pointer to the string containing escape sequences to interpret. |
Definition at line 30 of file interpret_escapes.c.
30 {
31 char *ptr;
32 long count;
33
34 ptr = s;
35 while (*s) {
36 if (*s == '"') {
37 do {
38 *ptr++ = *s++;
39 } while (*s != '"' && *s);
40 if (*s)
41 *ptr++ = *s++;
42 } else if (*s != '\\')
43 *ptr++ = *s++;
44 else {
45 s++;
46 if (!*s) {
47 *ptr++ = '\\';
48 *ptr++ = 0;
49 return;
50 }
51 switch (*s) {
52 case '\\':
53 *ptr++ = '\\';
54 s++;
55 break;
56 case 'n':
57 *ptr++ = '\n';
58 s++;
59 break;
60 case 't':
61 *ptr++ = '\t';
62 s++;
63 break;
64 default:
65 if (*s >= '0' && *s <= '9') {
66 *ptr = 0;
67 count = 0;
68 while (++count <= 3 && *s >= '0' && *s <= '9')
69 *ptr = 8 * (*ptr) + *s++ - '0';
70 ptr++;
71 } else {
72 *ptr++ = '\\';
73 }
74 break;
75 }
76 }
77 }
78 *ptr = 0;
79}