commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang Strings.java
Date Mon, 01 Jul 2002 20:59:07 GMT
scolebourne    2002/07/01 13:59:07

  Modified:    lang/src/java/org/apache/commons/lang Strings.java
  Log:
  Patch from Rand McNeely
  Optimise three methods
  
  Revision  Changes    Path
  1.8       +16 -7     jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/Strings.java
  
  Index: Strings.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/src/java/org/apache/commons/lang/Strings.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Strings.java	21 Jun 2002 05:20:36 -0000	1.7
  +++ Strings.java	1 Jul 2002 20:59:07 -0000	1.8
  @@ -85,6 +85,7 @@
    * @author <a href="mailto:gcoladonato@yahoo.com">Greg Coladonato</a>
    * @author <a href="mailto:bayard@generationjava.com">Bayard</a>
    * @author <a href="mailto:ed@apache.org">Ed Korthof</a>
  + * @author <a href="mailto:rand_mcneely@yahoo.com>Rand McNeely</a>
    * @version $Id$
    */
   public class Strings
  @@ -474,7 +475,10 @@
        * @return String uncapitalised
        */
       static public String uncapitalise(String str) {
  -        return str.substring(0,1).toLowerCase() + str.substring(1);
  +        return new StringBuffer(str.length())
  +            .append(Character.toLowerCase(str.charAt(0)))
  +            .append(str.substring(1))
  +            .toString();
       }
   
       /**
  @@ -486,8 +490,11 @@
        * @return String capitalised
        */
       static public String capitalise(String str) {
  -        return "" + Character.toTitleCase(str.charAt(0)) + str.substring(1);
  -    }
  +		return new StringBuffer(str.length())
  +			.append(Character.toTitleCase(str.charAt(0)))
  +			.append(str.substring(1))
  +			.toString();
  +	}
   
       /**
        * Replace a string with another string inside a larger string, once.
  @@ -557,9 +564,11 @@
        * @return String with overlayed text
        */
       static public String overlayString(String text, String overlay, int start, int end)
{
  -        String pre = text.substring(0, start);
  -        String post = text.substring(end);
  -        return pre+overlay+post;
  +        return new StringBuffer(start + overlay.length() + text.length() - end + 1)
  +			.append(text.substring(0, start))
  +			.append(overlay)
  +			.append(text.substring(end))
  +			.toString();
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message