#include <string.h>
#include <ctype.h>
+#include <yaz/querytowrbuf.h>
#include <yaz/ccl.h>
static void ccl_pquery_indent(WRBUF w, struct ccl_rpn_node *p, int indent);
static void ccl_prterm(WRBUF w, const char *term)
{
- if (!*term)
- wrbuf_puts(w, "\"\"");
- else
- {
- const char *cp = term;
- for (; *cp; cp++)
- {
- if (*cp == ' ' || *cp == '\\')
- wrbuf_putc(w, '\\');
- wrbuf_putc(w, *cp);
- }
- }
- wrbuf_puts(w, " ");
+ yaz_encode_pqf_term(w, term, strlen(term));
}
static void ccl_pquery_indent(WRBUF w, struct ccl_rpn_node *p, int indent)
*/
/** \file querytowrbuf.c
- \brief Query to WRBUF (to strings)
+ \brief Convert Z39.50 Z_Query to PQF (as WRBUF string)
*/
#include <stdio.h>
#include <yaz/querytowrbuf.h>
#include <yaz/oid_db.h>
-static void yaz_term_to_wrbuf(WRBUF b, const char *term, int len)
+void yaz_encode_pqf_term(WRBUF b, const char *term, int len)
{
int i;
for (i = 0; i < len; i++)
switch (zapt->term->which)
{
case Z_Term_general:
- yaz_term_to_wrbuf(b, (const char *)zapt->term->u.general->buf,
- zapt->term->u.general->len);
+ yaz_encode_pqf_term(b, (const char *)zapt->term->u.general->buf,
+ zapt->term->u.general->len);
break;
case Z_Term_characterString:
wrbuf_printf(b, "@term string ");
- yaz_term_to_wrbuf(b, zapt->term->u.characterString,
- strlen(zapt->term->u.characterString));
+ yaz_encode_pqf_term(b, zapt->term->u.characterString,
+ strlen(zapt->term->u.characterString));
break;
case Z_Term_numeric:
wrbuf_printf(b, "@term numeric %d ", *zapt->term->u.numeric);
else if (zs->u.simple->which == Z_Operand_resultSetId)
{
wrbuf_printf(b, "@set ");
- yaz_term_to_wrbuf(b, zs->u.simple->u.resultSetId,
- strlen(zs->u.simple->u.resultSetId));
+ yaz_encode_pqf_term(b, zs->u.simple->u.resultSetId,
+ strlen(zs->u.simple->u.resultSetId));
}
else
wrbuf_printf (b, "(unknown simple structure)");
YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
- YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 a,\\ b "));
+ YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 \"a, b\" "));
YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
- YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 a\\ -\\ b "));
+ YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 \"a - b\" "));
ccl_qual_rm(&bibset);
}