2 Copyright (C) 2004, 2005, 2006 John E. Davis
4 This file is part of the S-Lang Library.
6 Trimmed down for use in GNU Midnight Commander.
8 The S-Lang Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The S-Lang Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
33 char *SLmake_string(char *str
)
35 return SLmake_nstring(str
, strlen (str
));
38 char *SLmake_nstring (char *str
, unsigned int n
)
42 if (NULL
== (ptr
= SLmalloc(n
+ 1)))
46 SLMEMCPY (ptr
, str
, n
);
52 * This function assumes that the initial \ char has been removed.
54 char *_pSLexpand_escaped_char(char *p
, SLwchar_Type
*ch
, int *isunicodep
)
58 SLwchar_Type num
, base
= 0;
69 default: num
= ch1
; break;
70 case 'n': num
= '\n'; break;
71 case 't': num
= '\t'; break;
72 case 'v': num
= '\v'; break;
73 case 'b': num
= '\b'; break;
74 case 'r': num
= '\r'; break;
75 case 'f': num
= '\f'; break;
76 case 'E': case 'e': num
= 27; break;
81 case '0': case '1': case '2': case '3':
82 case '4': case '5': case '6': case '7':
84 base
= 8; i
= 2; num
= ch1
- '0';
87 case 'd': /* decimal -- S-Lang extension */
107 while (p
[i
] && (p
[i
] != '}'))
111 SLang_verror (SL_SYNTAX_ERROR
, "Escaped character missing closing }.");
114 /* The meaning of \x{...} is mode dependent. If in UTF-8 mode, then
115 * \x{...} always generates a unicode character. Otherwise, the
116 * meaning of \x{...} depends upon the number of characters enclosed
117 * by the brace. If there are less than 3, then assume no unicode.
118 * If greater than or equal to 3, then assume unicode.
120 if (isunicode
== 0) /* \x... */
121 isunicode
= _pSLinterp_UTF8_Mode
|| (i
> 2);
133 if ((ch1
<= max
) && (ch1
>= '0'))
135 num
= base
* num
+ (ch1
- '0');
140 if ((ch1
< 'a') || ((ch1
> 'f'))) break;
141 num
= base
* num
+ 10 + (ch1
- 'a');
151 SLang_verror (SL_SYNTAX_ERROR
, "Malformed escaped character.");
157 if (isunicodep
!= NULL
)
158 *isunicodep
= isunicode
;