X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLNode.java;h=3d16a37636653ddfbedcb760f30c67fa36997986;hb=ac8fb2ba7ecad42eb920c65b7056e3a3e677275c;hp=baa6cad12d7adc6a2c4ff00695c7fffa02d09186;hpb=a8088802d7221b9dc30c967bb8517fe3b089c414;p=cql-java-moved-to-github.git diff --git a/src/org/z3950/zing/cql/CQLNode.java b/src/org/z3950/zing/cql/CQLNode.java index baa6cad..3d16a37 100644 --- a/src/org/z3950/zing/cql/CQLNode.java +++ b/src/org/z3950/zing/cql/CQLNode.java @@ -1,4 +1,4 @@ -// $Id: CQLNode.java,v 1.5 2002-10-27 00:46:25 mike Exp $ +// $Id: CQLNode.java,v 1.6 2002-10-29 10:15:58 mike Exp $ package org.z3950.zing.cql; @@ -7,7 +7,7 @@ package org.z3950.zing.cql; * Represents a node in a CQL parse-tree ... * ### * - * @version $Id: CQLNode.java,v 1.5 2002-10-27 00:46:25 mike Exp $ + * @version $Id: CQLNode.java,v 1.6 2002-10-29 10:15:58 mike Exp $ */ public abstract class CQLNode { abstract String toXCQL(int level); @@ -21,14 +21,36 @@ public abstract class CQLNode { return x; } + // XML Quote -- + // s/&/&/g; + // s//>/g; + // This is hideously inefficient, but I just don't see a better + // way using the standard JAVA library. + // protected String xq(String str) { - // XML Quote - // ### s/&/&/g; - // s//>/g; + str = replace(str, "&", "&"); + str = replace(str, "<", "<"); + str = replace(str, ">", ">"); return str; } + String replace(String str, String from, String to) { + StringBuffer sb = new StringBuffer(); + int ix; // index of next `from' + int offset = 0; // index of previous `from' + length(from) + + while ((ix = str.indexOf(from, offset)) != -1) { + sb.append(str.substring(offset, ix)); + sb.append(to); + offset = ix + from.length(); + } + + // End of string: append last bit and we're done + sb.append(str.substring(offset)); + return sb.toString(); + } + // Test harness public static void main (String[] args) { CQLNode n1 = new CQLTermNode("dc.author", "=", "kernighan");