fix is_quoted() (reported "aaa\\\"bbb" as unquoted)

This commit is contained in:
stefan schippers 2024-10-31 11:06:19 +01:00
parent 4befd4765c
commit 65bd4ce766
1 changed files with 16 additions and 8 deletions

View File

@ -872,32 +872,40 @@ void check_unique_names(int rename)
}
static int is_quoted(const char *s)
{
size_t len = strlen(s);
if(s[0] == '"' && s[len - 1] == '"') return 1;
return 0;
}
int xis_quoted(const char *s)
{
int c, escape = 0;
int openquote = 0;
int closequote = 0;
while( (c = *s++) ) {
escape = 0;
if(c == '\\' && !escape) {
escape = 1;
c = *s++;
} else escape = 0;
}
if(c == '"' && !escape && !openquote ) {
openquote = 1;
continue;
}
else if(c == '"' && !escape && openquote && !closequote) {
closequote = 1;
continue;
}
else if(c == '"' && !escape ) {
return 0;
}
if(!isspace(c) && !openquote) return 0;
if(!isspace(c) && openquote && closequote) return 0;
else if(!isspace(c) && !openquote) {
return 0;
}
else if(!isspace(c) && openquote && closequote) {
return 0;
}
}
if(openquote && closequote) return 1;
return 0;