@Test public void finds_table_cells() { GherkinLine gherkinLine = new GherkinLine(" | \tred \t| \tblue \t| \t\uD83E\uDD52\uD83E\uDD52\uD83E\uDD52 \t| \tgreen \t|", line); GherkinLineSpan redSpan = gherkinLine.getTableCells().get(0); GherkinLineSpan blueSpan = gherkinLine.getTableCells().get(1); GherkinLineSpan emojiSpan = gherkinLine.getTableCells().get(2); GherkinLineSpan greenSpan = gherkinLine.getTableCells().get(3); assertEquals("red", redSpan.text); assertEquals(11, redSpan.column); assertEquals("blue", blueSpan.text); assertEquals(21, blueSpan.column); assertEquals("\uD83E\uDD52\uD83E\uDD52\uD83E\uDD52", emojiSpan.text); assertEquals(32, emojiSpan.column); assertEquals("green", greenSpan.text); assertEquals(42, greenSpan.column); }
@Override public List<GherkinLineSpan> getTableCells() { List<GherkinLineSpan> lineSpans = new ArrayList<>(); StringBuilder cellBuilder = new StringBuilder(); boolean beforeFirst = true; int col = 0; int cellStart = 0; boolean escape = false; PrimitiveIterator.OfInt iterator = lineText.codePoints().iterator(); while (iterator.hasNext()) { int c = iterator.next(); if (escape) { switch (c) { case 'n': cellBuilder.append('\n'); break; case '\\': cellBuilder.append('\\'); break; case '|': cellBuilder.append('|'); break; default: cellBuilder.append("\\"); cellBuilder.appendCodePoint(c); break; } escape = false; } else { if (c == '\\') { escape = true; } else if (c == '|') { if (beforeFirst) { beforeFirst = false; } else { String cell = cellBuilder.toString(); String leftTrimmedCell = ltrimKeepNewLines(cell); int cellIndent = symbolCount(cell) - symbolCount(leftTrimmedCell); lineSpans.add(new GherkinLineSpan(cellStart + cellIndent + OFFSET, rtrimKeepNewLines(leftTrimmedCell))); } cellBuilder = new StringBuilder(); cellStart = col + 1; } else { cellBuilder.appendCodePoint(c); } } col++; } return lineSpans; }
GherkinLine implements IGherkinLine { @Override public List<GherkinLineSpan> getTableCells() { List<GherkinLineSpan> lineSpans = new ArrayList<>(); StringBuilder cellBuilder = new StringBuilder(); boolean beforeFirst = true; int col = 0; int cellStart = 0; boolean escape = false; PrimitiveIterator.OfInt iterator = lineText.codePoints().iterator(); while (iterator.hasNext()) { int c = iterator.next(); if (escape) { switch (c) { case 'n': cellBuilder.append('\n'); break; case '\\': cellBuilder.append('\\'); break; case '|': cellBuilder.append('|'); break; default: cellBuilder.append("\\"); cellBuilder.appendCodePoint(c); break; } escape = false; } else { if (c == '\\') { escape = true; } else if (c == '|') { if (beforeFirst) { beforeFirst = false; } else { String cell = cellBuilder.toString(); String leftTrimmedCell = ltrimKeepNewLines(cell); int cellIndent = symbolCount(cell) - symbolCount(leftTrimmedCell); lineSpans.add(new GherkinLineSpan(cellStart + cellIndent + OFFSET, rtrimKeepNewLines(leftTrimmedCell))); } cellBuilder = new StringBuilder(); cellStart = col + 1; } else { cellBuilder.appendCodePoint(c); } } col++; } return lineSpans; } }
GherkinLine implements IGherkinLine { @Override public List<GherkinLineSpan> getTableCells() { List<GherkinLineSpan> lineSpans = new ArrayList<>(); StringBuilder cellBuilder = new StringBuilder(); boolean beforeFirst = true; int col = 0; int cellStart = 0; boolean escape = false; PrimitiveIterator.OfInt iterator = lineText.codePoints().iterator(); while (iterator.hasNext()) { int c = iterator.next(); if (escape) { switch (c) { case 'n': cellBuilder.append('\n'); break; case '\\': cellBuilder.append('\\'); break; case '|': cellBuilder.append('|'); break; default: cellBuilder.append("\\"); cellBuilder.appendCodePoint(c); break; } escape = false; } else { if (c == '\\') { escape = true; } else if (c == '|') { if (beforeFirst) { beforeFirst = false; } else { String cell = cellBuilder.toString(); String leftTrimmedCell = ltrimKeepNewLines(cell); int cellIndent = symbolCount(cell) - symbolCount(leftTrimmedCell); lineSpans.add(new GherkinLineSpan(cellStart + cellIndent + OFFSET, rtrimKeepNewLines(leftTrimmedCell))); } cellBuilder = new StringBuilder(); cellStart = col + 1; } else { cellBuilder.appendCodePoint(c); } } col++; } return lineSpans; } GherkinLine(String lineText, int line); }
GherkinLine implements IGherkinLine { @Override public List<GherkinLineSpan> getTableCells() { List<GherkinLineSpan> lineSpans = new ArrayList<>(); StringBuilder cellBuilder = new StringBuilder(); boolean beforeFirst = true; int col = 0; int cellStart = 0; boolean escape = false; PrimitiveIterator.OfInt iterator = lineText.codePoints().iterator(); while (iterator.hasNext()) { int c = iterator.next(); if (escape) { switch (c) { case 'n': cellBuilder.append('\n'); break; case '\\': cellBuilder.append('\\'); break; case '|': cellBuilder.append('|'); break; default: cellBuilder.append("\\"); cellBuilder.appendCodePoint(c); break; } escape = false; } else { if (c == '\\') { escape = true; } else if (c == '|') { if (beforeFirst) { beforeFirst = false; } else { String cell = cellBuilder.toString(); String leftTrimmedCell = ltrimKeepNewLines(cell); int cellIndent = symbolCount(cell) - symbolCount(leftTrimmedCell); lineSpans.add(new GherkinLineSpan(cellStart + cellIndent + OFFSET, rtrimKeepNewLines(leftTrimmedCell))); } cellBuilder = new StringBuilder(); cellStart = col + 1; } else { cellBuilder.appendCodePoint(c); } } col++; } return lineSpans; } GherkinLine(String lineText, int line); @Override int indent(); @Override void detach(); @Override String getLineText(int indentToRemove); @Override boolean isEmpty(); @Override boolean startsWith(String prefix); @Override String getRestTrimmed(int length); @Override List<GherkinLineSpan> getTags(); @Override List<GherkinLineSpan> getTableCells(); @Override boolean startsWithTitleKeyword(String text); }
GherkinLine implements IGherkinLine { @Override public List<GherkinLineSpan> getTableCells() { List<GherkinLineSpan> lineSpans = new ArrayList<>(); StringBuilder cellBuilder = new StringBuilder(); boolean beforeFirst = true; int col = 0; int cellStart = 0; boolean escape = false; PrimitiveIterator.OfInt iterator = lineText.codePoints().iterator(); while (iterator.hasNext()) { int c = iterator.next(); if (escape) { switch (c) { case 'n': cellBuilder.append('\n'); break; case '\\': cellBuilder.append('\\'); break; case '|': cellBuilder.append('|'); break; default: cellBuilder.append("\\"); cellBuilder.appendCodePoint(c); break; } escape = false; } else { if (c == '\\') { escape = true; } else if (c == '|') { if (beforeFirst) { beforeFirst = false; } else { String cell = cellBuilder.toString(); String leftTrimmedCell = ltrimKeepNewLines(cell); int cellIndent = symbolCount(cell) - symbolCount(leftTrimmedCell); lineSpans.add(new GherkinLineSpan(cellStart + cellIndent + OFFSET, rtrimKeepNewLines(leftTrimmedCell))); } cellBuilder = new StringBuilder(); cellStart = col + 1; } else { cellBuilder.appendCodePoint(c); } } col++; } return lineSpans; } GherkinLine(String lineText, int line); @Override int indent(); @Override void detach(); @Override String getLineText(int indentToRemove); @Override boolean isEmpty(); @Override boolean startsWith(String prefix); @Override String getRestTrimmed(int length); @Override List<GherkinLineSpan> getTags(); @Override List<GherkinLineSpan> getTableCells(); @Override boolean startsWithTitleKeyword(String text);  }