diff --git a/src/main/java/pipetableformatter/ColumnSplitter.java b/src/main/java/pipetableformatter/ColumnSplitter.java index d01bd83..48f62d7 100644 --- a/src/main/java/pipetableformatter/ColumnSplitter.java +++ b/src/main/java/pipetableformatter/ColumnSplitter.java @@ -11,7 +11,6 @@ public class ColumnSplitter implements Iterable, Iterator { private int startIndex = 0; private int length = 0; private boolean insideQuoted = false; - private boolean quoted = false; private Character delimiter; private int prevStartIndex; private int columnIndex; @@ -62,7 +61,7 @@ public String next() { prevStartIndex = startIndex; startIndex = endIndex + 1; columnIndex++; - return openQuotes(value); + return value; } private boolean hasMoreChars(int endIndex) { @@ -75,28 +74,10 @@ private boolean notDelimiter(int index) { private void detectQuoted(int index) { if (line.charAt(index) == '"') { - quoted = true; insideQuoted = !insideQuoted; } } - private String openQuotes(String value) { - if (quoted) { - quoted = false; - return replaceTwoQuotesWithOne(removeOpenAndCloseQuotes(value)); - } else { - return value; - } - } - - private String replaceTwoQuotesWithOne(String value) { - return value.replaceAll("\"\"", "\""); - } - - private String removeOpenAndCloseQuotes(String value) { - return value.replaceAll("(^ *\")|(\" *$)", ""); - } - public int currentColumnStartIndex() { return prevStartIndex + leadingSpaces; } @@ -128,7 +109,7 @@ public int getLeadingSpaces() { return leadingSpaces; } - public String getIndentetion() { + public String getIndentation() { if(leadingSpaces > 0) { return String.format("%" + leadingSpaces + "s", " "); } else { diff --git a/src/main/java/pipetableformatter/PipeTableParser.java b/src/main/java/pipetableformatter/PipeTableParser.java index a97d129..1842ba8 100644 --- a/src/main/java/pipetableformatter/PipeTableParser.java +++ b/src/main/java/pipetableformatter/PipeTableParser.java @@ -93,7 +93,7 @@ private PipeTable.Row splitForColumns(String line, boolean rowWithCaret, String PipeTable.Row row = new PipeTable.Row(cells, endOfLine); row.setCommented(tableRow.isCommented()); - row.setIndentation(tableRow.getIndentetion()); + row.setIndentation(tableRow.getIndentation()); row.setLeadingPipe(tableRow.hasLeadingPipe()); row.setTrailingPipe(tableRow.hasTrailingPipe()); diff --git a/src/test/java/pipetableformatter/PipeTableParserTest.java b/src/test/java/pipetableformatter/PipeTableParserTest.java index 625e090..2a00f35 100644 --- a/src/test/java/pipetableformatter/PipeTableParserTest.java +++ b/src/test/java/pipetableformatter/PipeTableParserTest.java @@ -77,21 +77,21 @@ public void splitsLineForColumnsByComma() { @Test public void ignoresCommasInsideDoubleQuotes() { PipeTable pipeTable = new PipeTableParser(" \"col1val1,col1val2\",column2").parse(); - assertThat(pipeTable.getValue(0, 0), is("col1val1,col1val2")); + assertThat(pipeTable.getValue(0, 0), is("\"col1val1,col1val2\"")); assertThat(pipeTable.getValue(0, 1), is("column2")); } @Test public void ignoresPipeInsideDoubleQuotes() { PipeTable pipeTable = new PipeTableParser(" |\"col1val1|col1val2\"|column2|").parse(); - assertThat(pipeTable.getValue(0, 0), is("col1val1|col1val2")); + assertThat(pipeTable.getValue(0, 0), is("\"col1val1|col1val2\"")); assertThat(pipeTable.getValue(0, 1), is("column2")); } @Test public void treatsTwoDoubleQuotesInsideQuotesAsOne() { PipeTable pipeTable = new PipeTableParser(" |\"val1\"\"val2\"|column2|").parse(); - assertThat(pipeTable.getValue(0, 0), is("val1\"val2")); + assertThat(pipeTable.getValue(0, 0), is("\"val1\"\"val2\"")); } @Test