Added yaz_encode_pqf_term to encode PQF strings.
authorAdam Dickmeiss <adam@indexdata.dk>
Sat, 25 Oct 2008 20:08:47 +0000 (22:08 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Sat, 25 Oct 2008 20:08:47 +0000 (22:08 +0200)
Added yaz_encode_pqf_term to encode PQF strings. This function is used
by yaz_rpnquery_to_wrbuf and CCL to PQF conversion utilities (ccl_pquery,
ccl_pr_tree).

include/yaz/querytowrbuf.h
src/cclptree.c
src/querytowrbuf.c
test/tstccl.c

index 000787b..7a08880 100644 (file)
@@ -44,6 +44,7 @@ YAZ_EXPORT void yaz_scan_to_wrbuf(WRBUF b, const Z_AttributesPlusTerm *zapt,
 YAZ_EXPORT void yaz_rpnquery_to_wrbuf(WRBUF b, const Z_RPNQuery *rpn);
 YAZ_EXPORT void wrbuf_diags(WRBUF b, int num_diagnostics,Z_DiagRec **diags);
 
+YAZ_EXPORT void yaz_encode_pqf_term(WRBUF b, const char *term, int len);
 YAZ_END_CDECL
 
 #endif
index 55d8ef8..7e38624 100644 (file)
@@ -14,6 +14,7 @@
 #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);
@@ -68,19 +69,7 @@ static void ccl_pquery_complex(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)
index 3a0847a..a120e88 100644 (file)
@@ -4,7 +4,7 @@
  */
 
 /** \file querytowrbuf.c
-    \brief Query to WRBUF (to strings)
+    \brief Convert Z39.50 Z_Query to PQF (as WRBUF string)
  */
 
 #include <stdio.h>
@@ -14,7 +14,7 @@
 #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++)
@@ -108,13 +108,13 @@ static void yaz_apt_to_wrbuf(WRBUF b, const Z_AttributesPlusTerm *zapt)
     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);
@@ -172,8 +172,8 @@ static void yaz_rpnstructure_to_wrbuf(WRBUF b, const Z_RPNStructure *zs)
         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)");
index daf2fb6..d8252b0 100644 (file)
@@ -194,9 +194,9 @@ void tst1(int pass)
     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);
 }