From: Adam Dickmeiss Date: Sat, 27 Aug 2011 13:38:59 +0000 (+0200) Subject: cql2ccl: quote term characters, except operators X-Git-Tag: v4.2.12~1 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=295502cfb885ae2dde3523d76bd691f01de3477c;p=yaz-moved-to-github.git cql2ccl: quote term characters, except operators Fixes #4584. --- diff --git a/src/cql2ccl.c b/src/cql2ccl.c index df6e863..ab358f6 100644 --- a/src/cql2ccl.c +++ b/src/cql2ccl.c @@ -26,36 +26,56 @@ static void pr_term(struct cql_node *cn, { while (cn) { - const char *cp; - for (cp = cn->u.st.term; *cp; cp++) + if (! *cn->u.st.term) /* empty term special case */ + pr("\"\"", client_data); + else { - char x[4]; - - if (*cp == '\\' && cp[1]) - { - x[0] = cp[0]; - x[1] = cp[1]; - x[2] = '\0'; - cp++; - } - else if (*cp == '#') - { - strcpy(x, "\\#"); - } - else if (*cp == '*') + const char *cp; + int quote_mode = 0; + for (cp = cn->u.st.term; *cp; cp++) { - strcpy(x, "?"); - } - else if (*cp == '?') - { - strcpy(x, "#"); - } - else - { - x[0] = *cp; - x[1] = '\0'; + char x[4]; + + if (*cp == '\\' && cp[1]) + { + x[0] = cp[0]; + x[1] = cp[1]; + x[2] = '\0'; + cp++; + pr(x, client_data); + } + else if (*cp == '*') + { + if (quote_mode) + { + pr("\"", client_data); + quote_mode = 0; + } + pr("?", client_data); + } + else if (*cp == '?') + { + if (quote_mode) + { + pr("\"", client_data); + quote_mode = 0; + } + pr("#", client_data); + } + else + { + if (!quote_mode) + { + pr("\"", client_data); + quote_mode = 1; + } + x[0] = *cp; + x[1] = '\0'; + pr(x, client_data); + } } - pr(x, client_data); + if (quote_mode) + pr("\"", client_data); } if (cn->u.st.extra_terms) pr(" ", client_data);