SDDSlib
Loading...
Searching...
No Matches
SDDS
mdblib
interpret_escapes.c
Go to the documentation of this file.
1
/**
2
* @file interpret_escapes.c
3
* @brief Provides functionality to interpret C escape sequences in strings.
4
*
5
* This file contains functions to interpret C-style escape sequences such as
6
* \n (newline), \t (tab), and octal specifications like \ddd.
7
*
8
* @copyright
9
* - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
10
* - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
11
*
12
* @license
13
* This file is distributed under the terms of the Software License Agreement
14
* found in the file LICENSE included with this distribution.
15
*
16
* @author M. Borland, C. Saunders, R. Soliday
17
*/
18
19
#include "mdb.h"
20
21
/**
22
* @brief Interpret C escape sequences in a string.
23
*
24
* This function processes the input string and replaces C-style escape sequences
25
* (such as \n for newline, \t for tab, and octal sequences like \ddd) with their
26
* corresponding characters.
27
*
28
* @param s Pointer to the string containing escape sequences to interpret.
29
*/
30
void
interpret_escapes
(
char
*s) {
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
}
interpret_escapes
void interpret_escapes(char *s)
Interpret C escape sequences in a string.
Definition
interpret_escapes.c:30
Generated by
1.12.0