1 // $Id: Utils.java,v 1.2 2002-11-06 00:05:58 mike Exp $
3 package org.z3950.zing.cql;
7 * Utility functions for the org.z3950.zing.cql package.
8 * Not intended for use outside this package.
10 * @version $Id: Utils.java,v 1.2 2002-11-06 00:05:58 mike Exp $
13 static String indent(int level) {
25 // This is hideously inefficient, but I just don't see a better
26 // way using the standard JAVA library.
28 static String xq(String str) {
29 str = replaceString(str, "&", "&");
30 str = replaceString(str, "<", "<");
31 str = replaceString(str, ">", ">");
35 // I can't _believe_ I have to write this by hand in 2002 ...
36 static String replaceString(String str, String from, String to) {
37 StringBuffer sb = new StringBuffer();
38 int ix; // index of next `from'
39 int offset = 0; // index of previous `from' + length(from)
41 while ((ix = str.indexOf(from, offset)) != -1) {
42 sb.append(str.substring(offset, ix));
44 offset = ix + from.length();
47 // End of string: append last bit and we're done
48 sb.append(str.substring(offset));