You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Tom Amiro <To...@Sun.COM> on 2002/04/30 19:36:17 UTC

Re: cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util Util.java

No bug number?

T

santiagopg@apache.org wrote:
> 
> 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

-- 
 Tom Amiro -- SQA Engineer
 Sun XML Technology Development
 voice: 781-442-0589 Fax: 781-442-1437
 eMail: tom.amiro@.sun.com