Author: bayard
Date: Sat May 16 08:18:46 2009
New Revision: 775429
URL: http://svn.apache.org/viewvc?rev=775429&view=rev
Log:
Started cloning the input character array. Record in LANG-489 for migration
guide.
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java?rev=775429&r1=775428&r2=775429&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java
(original)
+++
commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java
Sat May 16 08:18:46 2009
@@ -22,6 +22,8 @@
import java.util.ListIterator;
import java.util.NoSuchElementException;
+import org.apache.commons.lang.ArrayUtils;
+
/**
* Tokenizes a string based based on delimiters (separators)
* and supporting quoting and ignored character concepts.
@@ -319,22 +321,16 @@
/**
* Constructs a tokenizer splitting on space, tab, newline and formfeed
* as per StringTokenizer.
- * <p>
- * The input character array is not cloned, and must not be altered after
- * passing in to this method.
*
* @param input the string which is to be parsed, not cloned
*/
public StrTokenizer(char[] input) {
super();
- this.chars = input;
+ this.chars = ArrayUtils.clone(input);
}
/**
* Constructs a tokenizer splitting on the specified character.
- * <p>
- * The input character array is not cloned, and must not be altered after
- * passing in to this method.
*
* @param input the string which is to be parsed, not cloned
* @param delim the field delimiter character
@@ -346,9 +342,6 @@
/**
* Constructs a tokenizer splitting on the specified string.
- * <p>
- * The input character array is not cloned, and must not be altered after
- * passing in to this method.
*
* @param input the string which is to be parsed, not cloned
* @param delim the field delimiter string
@@ -360,9 +353,6 @@
/**
* Constructs a tokenizer splitting using the specified delimiter matcher.
- * <p>
- * The input character array is not cloned, and must not be altered after
- * passing in to this method.
*
* @param input the string which is to be parsed, not cloned
* @param delim the field delimiter matcher
@@ -375,9 +365,6 @@
/**
* Constructs a tokenizer splitting on the specified delimiter character
* and handling quotes using the specified quote character.
- * <p>
- * The input character array is not cloned, and must not be altered after
- * passing in to this method.
*
* @param input the string which is to be parsed, not cloned
* @param delim the field delimiter character
@@ -391,9 +378,6 @@
/**
* Constructs a tokenizer splitting using the specified delimiter matcher
* and handling quotes using the specified quote matcher.
- * <p>
- * The input character array is not cloned, and must not be altered after
- * passing in to this method.
*
* @param input the string which is to be parsed, not cloned
* @param delim the field delimiter character
@@ -499,16 +483,13 @@
* Reset this tokenizer, giving it a new input string to parse.
* In this manner you can re-use a tokenizer with the same settings
* on multiple input lines.
- * <p>
- * The input character array is not cloned, and must not be altered after
- * passing in to this method.
*
* @param input the new character array to tokenize, not cloned, null
sets no text to parse
* @return this, to enable chaining
*/
public StrTokenizer reset(char[] input) {
reset();
- this.chars = input;
+ this.chars = ArrayUtils.clone(input);
return this;
}
Modified:
commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java?rev=775429&r1=775428&r2=775429&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java
(original)
+++
commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java
Sat May 16 08:18:46 2009
@@ -592,12 +592,12 @@
StrTokenizer tokenizer = new StrTokenizer(input);
// Start sanity check
assertEquals("a", tokenizer.nextToken());
- tokenizer.reset();
+ tokenizer.reset(input);
assertEquals("a", tokenizer.nextToken());
// End sanity check
StrTokenizer clonedTokenizer = (StrTokenizer) tokenizer.clone();
input[0] = 'b';
- tokenizer.reset();
+ tokenizer.reset(input);
assertEquals("b", tokenizer.nextToken());
assertEquals("a", clonedTokenizer.nextToken());
}
@@ -723,9 +723,8 @@
public void testReset_charArray() {
StrTokenizer tok = new StrTokenizer("x x x");
- char[] array = new char[] {'a', ' ', 'c'};
+ char[] array = new char[] {'a', 'b', 'c'};
tok.reset(array);
- array[1] = 'b'; // test linked array
assertEquals("abc", tok.next());
assertEquals(false, tok.hasNext());