Skip to content

Commit

Permalink
BATCH-1995: Updated to handle delimitors at the beginning and end of …
Browse files Browse the repository at this point in the history
…a line
  • Loading branch information
mminella committed Apr 21, 2013
1 parent 7801dee commit 903f506
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ michael
minella
accessors
subclassing
ajax
javascript
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ protected List<String> doTokenize(String line) {
int fieldCount = 0;

for (int i = 0; i < length; i++) {

char currentChar = chars[i];
boolean isEnd = (i == (length - 1));

Expand All @@ -154,7 +153,7 @@ protected List<String> doTokenize(String line) {
int endPosition = (isEnd ? (length - lastCut) : (i - lastCut));

if (isEnd && isDelimiter) {
endPosition--;
endPosition = endPosition - delimiter.length();
}
else if (!isEnd){
endPosition = (endPosition - delimiter.length()) + 1;
Expand Down Expand Up @@ -233,7 +232,7 @@ private boolean isQuoted(String value) {
private boolean isDelimiter(char[] chars, int i, String token) {
boolean result = false;

if(i >= token.length()) {
if(i >= token.length() - 1) {
String end = new String(chars, (i-token.length()) + 1, token.length());
if(token.equals(end)) {
result = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ public void testDelimitedLineTokenizerString() {
assertEquals("c", line.readString(1));
}

@Test
public void testDelimitedLineTokenizerStringBeginningOfLine() {
AbstractLineTokenizer tokenizer = new DelimitedLineTokenizer(" | ");
FieldSet line = tokenizer.tokenize(" | a | b");
assertEquals(3, line.getFieldCount());
assertEquals("", line.readString(0));
assertEquals("a", line.readString(1));
assertEquals("b", line.readString(2));
}

@Test
public void testDelimitedLineTokenizerStringEndOfLine() {
AbstractLineTokenizer tokenizer = new DelimitedLineTokenizer(" | ");
FieldSet line = tokenizer.tokenize("a | b | ");
assertEquals(3, line.getFieldCount());
assertEquals("a", line.readString(0));
assertEquals("b", line.readString(1));
assertEquals("", line.readString(2));
}

@Test
public void testDelimitedLineTokenizerNewlineToken() {
AbstractLineTokenizer tokenizer = new DelimitedLineTokenizer("\n");
Expand Down

0 comments on commit 903f506

Please sign in to comment.