dlr 01/08/31 14:54:06
Modified: util/src/java/org/apache/commons/util StringUtils.java
Log:
Added check for null in replace() core method.
Revision Changes Path
1.15 +10 -3
jakarta-commons-sandbox/util/src/java/org/apache/commons/util/StringUtils.java
Index: StringUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/util/src/java/org/apache/commons/util/StringUtils.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -u -r1.14 -r1.15
--- StringUtils.java 2001/08/27 02:22:18 1.14
+++ StringUtils.java 2001/08/31 21:54:06 1.15
@@ -81,7 +81,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Greg Coladonato</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Bayard</a>
- * @version $Id: StringUtils.java,v 1.14 2001/08/27 02:22:18 dlr Exp $
+ * @version $Id: StringUtils.java,v 1.15 2001/08/31 21:54:06 dlr Exp $
*/
public class StringUtils
{
@@ -488,8 +488,10 @@
}
/**
- * Replace a string with another string inside a larger string, for
- * the first n values of the search string.
+ * Replace a string with another string inside a larger string,
+ * for the first <code>max</code> values of the search string. A
+ * <code>null</code> reference is passed to this method is a
+ * no-op.
*
* @param text Text to search and replace in.
* @param repl String to search for
@@ -501,6 +503,11 @@
public static String replace(String text, String repl, String with,
int max)
{
+ if (text == null)
+ {
+ return null;
+ }
+
StringBuffer buf = new StringBuffer(text.length());
int start = 0, end = 0;
while ( (end = text.indexOf(repl, start)) != -1 )