better backslash handling in translate3()
This commit is contained in:
parent
a725838850
commit
d06e999daf
12
src/token.c
12
src/token.c
|
|
@ -4415,6 +4415,7 @@ const char *translate3(const char *s, int eat_escapes, const char *s1, const cha
|
||||||
const char *value;
|
const char *value;
|
||||||
int escape=0;
|
int escape=0;
|
||||||
char *value1 = NULL;
|
char *value1 = NULL;
|
||||||
|
const char *escape_pos = NULL;
|
||||||
|
|
||||||
|
|
||||||
if(!s || !xctx) {
|
if(!s || !xctx) {
|
||||||
|
|
@ -4426,11 +4427,12 @@ const char *translate3(const char *s, int eat_escapes, const char *s1, const cha
|
||||||
my_strdup2(_ALLOC_ID_, &result, "");
|
my_strdup2(_ALLOC_ID_, &result, "");
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
c=*s++;
|
c=*s;
|
||||||
|
|
||||||
if(c=='\\') {
|
if(c=='\\') {
|
||||||
escape=1;
|
escape=1;
|
||||||
if(eat_escapes) c=*s++;
|
escape_pos = s;
|
||||||
|
if(eat_escapes) { s++; c=*s; }
|
||||||
}
|
}
|
||||||
|
|
||||||
space=SPACE(c);
|
space=SPACE(c);
|
||||||
|
|
@ -4442,7 +4444,9 @@ const char *translate3(const char *s, int eat_escapes, const char *s1, const cha
|
||||||
)
|
)
|
||||||
) state=TOK_SEP;
|
) state=TOK_SEP;
|
||||||
|
|
||||||
if( c != '\\' && escape ) escape = 0;
|
if( s > escape_pos ) escape = 0;
|
||||||
|
|
||||||
|
s++;
|
||||||
|
|
||||||
STR_ALLOC(&token, token_pos, &sizetok);
|
STR_ALLOC(&token, token_pos, &sizetok);
|
||||||
if(state==TOK_TOKEN) token[token_pos++]=(char)c;
|
if(state==TOK_TOKEN) token[token_pos++]=(char)c;
|
||||||
|
|
@ -4465,7 +4469,7 @@ const char *translate3(const char *s, int eat_escapes, const char *s1, const cha
|
||||||
my_free(_ALLOC_ID_, &value1);
|
my_free(_ALLOC_ID_, &value1);
|
||||||
}
|
}
|
||||||
token_pos = 0;
|
token_pos = 0;
|
||||||
if(c == '@' || c == '%') s--;
|
if(c == '@' || c == '%') s--; /* these token separators are also identifiers for next token: push them back */
|
||||||
else {
|
else {
|
||||||
char ch[2];
|
char ch[2];
|
||||||
ch[0] = (char)c;
|
ch[0] = (char)c;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue