scolebourne 2003/07/30 15:17:00
Modified: lang/src/java/org/apache/commons/lang CharSetUtils.java
Log:
Update javadoc to better describe method
Revision Changes Path
1.16 +16 -10
jakarta-commons/lang/src/java/org/apache/commons/lang/CharSetUtils.java
Index: CharSetUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/CharSetUtils.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- CharSetUtils.java 30 Jul 2003 00:08:38 -0000 1.15
+++ CharSetUtils.java 30 Jul 2003 22:17:00 -0000 1.16
@@ -320,7 +320,8 @@
}
/**
- * <p>Translate characters in a String.</p>
+ * <p>Translate characters in a String.
+ * This is a multi character search and replace routine.</p>
*
* <p>An example is:</p>
* <ul>
@@ -331,26 +332,31 @@
* <p>If the length of characters to search for is greater than the
* length of characters to replace, then the last character is
* used.</p>
+ *
+ * <pre>
+ * CharSetUtils.translate(null, *, *) = null
+ * CharSetUtils.translate("", *, *) = ""
+ * </pre>
*
* @param str String to replace characters in, may be null
- * @param repl String to find that will be replaced, must not be null
- * @param with String to put into the target String, must not be null or empty
("")
+ * @param searchChars a set of characters to search for, must not be null
+ * @param replaceChars a set of characters to replace, must not be null or
empty ("")
* @return translated String, <code>null</code> if null string input
* @throws NullPointerException if <code>with</code> or <code>repl</code>
* is <code>null</code>
* @throws ArrayIndexOutOfBoundsException if <code>with</code> is empty ("")
*/
- public static String translate(String str, String repl, String with) {
- if (str == null) {
- return null;
+ public static String translate(String str, String searchChars, String
replaceChars) {
+ if (str == null || str.length() == 0) {
+ return str;
}
StringBuffer buffer = new StringBuffer(str.length());
char[] chrs = str.toCharArray();
- char[] withChrs = with.toCharArray();
+ char[] withChrs = replaceChars.toCharArray();
int sz = chrs.length;
- int withMax = with.length() - 1;
+ int withMax = replaceChars.length() - 1;
for(int i=0; i<sz; i++) {
- int idx = repl.indexOf(chrs[i]);
+ int idx = searchChars.indexOf(chrs[i]);
if(idx != -1) {
if(idx > withMax) {
idx = withMax;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]