@Test public void testScan() { TextSplitter sut = new TextSplitter(13, 10, "<", ">"); List<String> pieces = sut.split(" aaa bbb ccc d eee fff ggg hhh i "); assertPieces(pieces, "aaa bbb>", "<ccc d>", "<eee fff>", "<ggg hhh i"); }
public List<String> split(final String originalInputText) { List<String> piecesList = new ArrayList<String>(); if (originalInputText == null) { return piecesList; } int startIdx = 0; String inputText = originalInputText.trim(); int inputLength = inputText.length(); while (startIdx < inputLength) { if (Character.isWhitespace(inputText.charAt(startIdx))) { startIdx++; continue; } int useBlockSize = piecesList.isEmpty() ? firstBlockSize : blockSize; int remainingSize = inputLength - startIdx; if (remainingSize > useBlockSize) { int scanIdx = startIdx + useBlockSize - continueToMarkLength; while (scanIdx > startIdx && !Character.isWhitespace(inputText.charAt(scanIdx))) { scanIdx--; } if (scanIdx == startIdx) { scanIdx = startIdx + useBlockSize - continueToMarkLength; } piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx, scanIdx).trim() + continueToMark); startIdx = scanIdx; } else { piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx)); break; } } return piecesList; }
TextSplitter { public List<String> split(final String originalInputText) { List<String> piecesList = new ArrayList<String>(); if (originalInputText == null) { return piecesList; } int startIdx = 0; String inputText = originalInputText.trim(); int inputLength = inputText.length(); while (startIdx < inputLength) { if (Character.isWhitespace(inputText.charAt(startIdx))) { startIdx++; continue; } int useBlockSize = piecesList.isEmpty() ? firstBlockSize : blockSize; int remainingSize = inputLength - startIdx; if (remainingSize > useBlockSize) { int scanIdx = startIdx + useBlockSize - continueToMarkLength; while (scanIdx > startIdx && !Character.isWhitespace(inputText.charAt(scanIdx))) { scanIdx--; } if (scanIdx == startIdx) { scanIdx = startIdx + useBlockSize - continueToMarkLength; } piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx, scanIdx).trim() + continueToMark); startIdx = scanIdx; } else { piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx)); break; } } return piecesList; } }
TextSplitter { public List<String> split(final String originalInputText) { List<String> piecesList = new ArrayList<String>(); if (originalInputText == null) { return piecesList; } int startIdx = 0; String inputText = originalInputText.trim(); int inputLength = inputText.length(); while (startIdx < inputLength) { if (Character.isWhitespace(inputText.charAt(startIdx))) { startIdx++; continue; } int useBlockSize = piecesList.isEmpty() ? firstBlockSize : blockSize; int remainingSize = inputLength - startIdx; if (remainingSize > useBlockSize) { int scanIdx = startIdx + useBlockSize - continueToMarkLength; while (scanIdx > startIdx && !Character.isWhitespace(inputText.charAt(scanIdx))) { scanIdx--; } if (scanIdx == startIdx) { scanIdx = startIdx + useBlockSize - continueToMarkLength; } piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx, scanIdx).trim() + continueToMark); startIdx = scanIdx; } else { piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx)); break; } } return piecesList; } TextSplitter(final int inFirstBlockSize, final int inBlockSize);  TextSplitter(final int inFirstBlockSize, final int inBlockSize, final String inContinuedFromMark,
            final String inContinueToMark); }
TextSplitter { public List<String> split(final String originalInputText) { List<String> piecesList = new ArrayList<String>(); if (originalInputText == null) { return piecesList; } int startIdx = 0; String inputText = originalInputText.trim(); int inputLength = inputText.length(); while (startIdx < inputLength) { if (Character.isWhitespace(inputText.charAt(startIdx))) { startIdx++; continue; } int useBlockSize = piecesList.isEmpty() ? firstBlockSize : blockSize; int remainingSize = inputLength - startIdx; if (remainingSize > useBlockSize) { int scanIdx = startIdx + useBlockSize - continueToMarkLength; while (scanIdx > startIdx && !Character.isWhitespace(inputText.charAt(scanIdx))) { scanIdx--; } if (scanIdx == startIdx) { scanIdx = startIdx + useBlockSize - continueToMarkLength; } piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx, scanIdx).trim() + continueToMark); startIdx = scanIdx; } else { piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx)); break; } } return piecesList; } TextSplitter(final int inFirstBlockSize, final int inBlockSize);  TextSplitter(final int inFirstBlockSize, final int inBlockSize, final String inContinuedFromMark,
            final String inContinueToMark); List<String> split(final String originalInputText); }
TextSplitter { public List<String> split(final String originalInputText) { List<String> piecesList = new ArrayList<String>(); if (originalInputText == null) { return piecesList; } int startIdx = 0; String inputText = originalInputText.trim(); int inputLength = inputText.length(); while (startIdx < inputLength) { if (Character.isWhitespace(inputText.charAt(startIdx))) { startIdx++; continue; } int useBlockSize = piecesList.isEmpty() ? firstBlockSize : blockSize; int remainingSize = inputLength - startIdx; if (remainingSize > useBlockSize) { int scanIdx = startIdx + useBlockSize - continueToMarkLength; while (scanIdx > startIdx && !Character.isWhitespace(inputText.charAt(scanIdx))) { scanIdx--; } if (scanIdx == startIdx) { scanIdx = startIdx + useBlockSize - continueToMarkLength; } piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx, scanIdx).trim() + continueToMark); startIdx = scanIdx; } else { piecesList.add((piecesList.isEmpty() ? "" : continuedFromMark) + inputText.substring(startIdx)); break; } } return piecesList; } TextSplitter(final int inFirstBlockSize, final int inBlockSize);  TextSplitter(final int inFirstBlockSize, final int inBlockSize, final String inContinuedFromMark,
            final String inContinueToMark); List<String> split(final String originalInputText);  }