xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From santiag...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util Util.java
Date Tue, 30 Apr 2002 17:16:51 GMT
santiagopg    02/04/30 10:16:51

  Modified:    java/src/org/apache/xalan/xsltc/compiler/util Util.java
  Log:
  Fixed a bug in replace() by writting a new (and more efficient) version.
  
  Revision  Changes    Path
  1.8       +20 -21    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Util.java
  
  Index: Util.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/Util.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Util.java	25 Apr 2002 20:45:27 -0000	1.7
  +++ Util.java	30 Apr 2002 17:16:51 -0000	1.8
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Util.java,v 1.7 2002/04/25 20:45:27 santiagopg Exp $
  + * @(#)$Id: Util.java,v 1.8 2002/04/30 17:16:51 santiagopg Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -155,36 +155,35 @@
       /**
        * Replace a certain character in a string with a new substring.
        */
  -    public static String replace(String base, char c, String str) {
  -	final int len = base.length() - 1;
  -	int pos;
  -	while ((pos = base.indexOf(c)) > -1) {
  -	    if (pos == 0) {
  -		final String after = base.substring(1);
  -		base = str + after;
  -	    }
  -	    else if (pos == len) {
  -		final String before = base.substring(0, pos);
  -		base = before + str;
  +    public static String replace(String base, char ch, String str) {
  +	return (base.indexOf(ch) < 0) ? base : 
  +	    replace(base, String.valueOf(ch), new String[] { str });
  +    }
  +
  +    public static String replace(String base, String delim, String[] str) {
  +	final int len = base.length();
  +	final StringBuffer result = new StringBuffer();
  +
  +	for (int i = 0; i < len; i++) {
  +	    final char ch = base.charAt(i);
  +	    final int k = delim.indexOf(ch);
  +
  +	    if (k >= 0) {
  +		result.append(str[k]);
   	    }
   	    else {
  -		final String before = base.substring(0, pos);
  -		final String after = base.substring(pos+1);
  -		base = before + str + after;
  +		result.append(ch);
   	    }
   	}
  -	return base;
  +	return result.toString();
       }
   
       /**
        * Replace occurances of '.', '-', '/' and ':'
        */
       public static String escape(String input) {
  -	input = replace(input, '.', "$dot$");
  -	input = replace(input, '-', "$dash$");
  -	input = replace(input, '/', "$slash$");
  -	input = replace(input, ':', "$colon$");
  -	return input;
  +	return replace(input, ".-/:", 
  +	    new String[] { "$dot$", "$dash$", "$slash$", "$colon$" });
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message