From 54de1464561d3b0cba5b89fd93b393550ee47e6b Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 31 Oct 2002 22:23:19 +0000 Subject: [PATCH] Oops -- forgot to add Utils.java. Now added. --- src/org/z3950/zing/cql/Utils.java | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/org/z3950/zing/cql/Utils.java diff --git a/src/org/z3950/zing/cql/Utils.java b/src/org/z3950/zing/cql/Utils.java new file mode 100644 index 0000000..3c06f7c --- /dev/null +++ b/src/org/z3950/zing/cql/Utils.java @@ -0,0 +1,51 @@ +// $Id: Utils.java,v 1.1 2002-10-31 22:23:19 mike Exp $ + +package org.z3950.zing.cql; + + +/** + * Utility functions for the org.z3950.zing.cql package. + * ## + * + * @version $Id: Utils.java,v 1.1 2002-10-31 22:23:19 mike Exp $ + */ +class Utils { + static String indent(int level) { + String x = ""; + while (level-- > 0) { + x += " "; + } + 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. + // + static String xq(String str) { + str = replaceString(str, "&", "&"); + str = replaceString(str, "<", "<"); + str = replaceString(str, ">", ">"); + return str; + } + + // I can't _believe_ I have to write this by hand in 2002 ... + static String replaceString(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(); + } +} -- 1.7.10.4