1 //////////////////////////////////////////////////////////////////////////////
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
23 //////////////////////////////////////////////////////////////////////////////
26 #include <AD/strings/charesc.h>
28 char * quote_string (char * buf
, const char * s
)
32 buf
= print_char(buf
,c
);
38 const char * parse_char(const char * s
, char& c
)
44 for (ch
= 0, count
= 0; *s
>= '0' && *s
<= '7' && count
< 3; s
++, count
++)
45 ch
= ch
* 8 + *s
- '0';
48 case 'n': c
= '\n'; break;
49 case 't': c
= '\t'; break;
55 if (isdigit(*s
)) digit1
= *s
- '0';
56 else if (*s
>= 'a' && *s
<= 'f') digit1
= *s
- 'a' + 10;
57 else if (*s
>= 'A' && *s
<= 'F') digit1
= *s
- 'A' + 10;
60 if (isdigit(*s
)) digit2
= *s
- '0';
61 else if (*s
>= 'a' && *s
<= 'f') digit2
= *s
- 'a' + 10;
62 else if (*s
>= 'A' && *s
<= 'F') digit2
= *s
- 'A' + 10;
64 c
= digit1
* 16 + digit2
;
73 char * print_char(char * s
, char c
)
76 *s
++ = '\\'; *s
++ = 'n'; *s
= '\0'; return s
;
77 } else if (c
== '\t') {
78 *s
++ = '\\'; *s
++ = 't'; *s
= '\0'; return s
;
79 } else if (c
== '\'' || c
== '\"' || c
== '\\') {
80 *s
++ = '\\'; *s
++ = c
; *s
= '\0'; return s
;
81 } else if (isprint(c
)) {
82 *s
++ = c
; *s
= '\0'; return s
;
87 s
[2] = (ch
/ 8) % 8 + '0';
94 const char * print_char(char c
)
95 { static char buf
[10];