From 295502cfb885ae2dde3523d76bd691f01de3477c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sat, 27 Aug 2011 15:38:59 +0200 Subject: [PATCH] cql2ccl: quote term characters, except operators Fixes #4584. --- src/cql2ccl.c | 74 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 27 deletions(-) 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); -- 1.7.10.4