@Test void threeLines() throws Exception { Document doc = parse("hello = world\r\nworld:earth\n key=val"); Sentence sentence = doc.getSection(0).getParagraph(0).getSentence(0); assertEquals("world", sentence.getContent()); assertEquals(1, sentence.getLineNumber()); assertEquals(offsets(1, range(8, 13)), sentence.getOffsetMap()); sentence = doc.getSection(1).getParagraph(0).getSentence(0); assertEquals("earth", sentence.getContent()); assertEquals(2, sentence.getLineNumber()); assertEquals(offsets(2, range(6, 11)), sentence.getOffsetMap()); sentence = doc.getSection(2).getParagraph(0).getSentence(0); assertEquals("val", sentence.getContent()); assertEquals(3, sentence.getLineNumber()); assertEquals(offsets(3, range(6, 9)), sentence.getOffsetMap()); }
@Override public Document parse(InputStream inputStream, Optional<String> fileName, SentenceExtractor sentenceExtractor, RedPenTokenizer tokenizer) throws RedPenException { Document.DocumentBuilder builder = Document.builder(tokenizer); fileName.ifPresent(builder::setFileName); try (PreprocessingReader reader = createReader(inputStream)) { String line; AtomicInteger lineNum = new AtomicInteger(0); while ((line = reader.readLine()) != null) { lineNum.incrementAndGet(); int keyStart = skipWhitespace(line, 0); if (keyStart == line.length()) continue; int valueStart = valueOffset(line, keyStart); addSentences(builder, sentenceExtractor, section(line, lineNum, valueStart, reader)); } builder.setPreprocessorRules(reader.getPreprocessorRules()); } catch (IOException e) { throw new RedPenException(e); } return builder.build(); }
PropertiesParser extends BaseDocumentParser { @Override public Document parse(InputStream inputStream, Optional<String> fileName, SentenceExtractor sentenceExtractor, RedPenTokenizer tokenizer) throws RedPenException { Document.DocumentBuilder builder = Document.builder(tokenizer); fileName.ifPresent(builder::setFileName); try (PreprocessingReader reader = createReader(inputStream)) { String line; AtomicInteger lineNum = new AtomicInteger(0); while ((line = reader.readLine()) != null) { lineNum.incrementAndGet(); int keyStart = skipWhitespace(line, 0); if (keyStart == line.length()) continue; int valueStart = valueOffset(line, keyStart); addSentences(builder, sentenceExtractor, section(line, lineNum, valueStart, reader)); } builder.setPreprocessorRules(reader.getPreprocessorRules()); } catch (IOException e) { throw new RedPenException(e); } return builder.build(); } }
PropertiesParser extends BaseDocumentParser { @Override public Document parse(InputStream inputStream, Optional<String> fileName, SentenceExtractor sentenceExtractor, RedPenTokenizer tokenizer) throws RedPenException { Document.DocumentBuilder builder = Document.builder(tokenizer); fileName.ifPresent(builder::setFileName); try (PreprocessingReader reader = createReader(inputStream)) { String line; AtomicInteger lineNum = new AtomicInteger(0); while ((line = reader.readLine()) != null) { lineNum.incrementAndGet(); int keyStart = skipWhitespace(line, 0); if (keyStart == line.length()) continue; int valueStart = valueOffset(line, keyStart); addSentences(builder, sentenceExtractor, section(line, lineNum, valueStart, reader)); } builder.setPreprocessorRules(reader.getPreprocessorRules()); } catch (IOException e) { throw new RedPenException(e); } return builder.build(); }  }
PropertiesParser extends BaseDocumentParser { @Override public Document parse(InputStream inputStream, Optional<String> fileName, SentenceExtractor sentenceExtractor, RedPenTokenizer tokenizer) throws RedPenException { Document.DocumentBuilder builder = Document.builder(tokenizer); fileName.ifPresent(builder::setFileName); try (PreprocessingReader reader = createReader(inputStream)) { String line; AtomicInteger lineNum = new AtomicInteger(0); while ((line = reader.readLine()) != null) { lineNum.incrementAndGet(); int keyStart = skipWhitespace(line, 0); if (keyStart == line.length()) continue; int valueStart = valueOffset(line, keyStart); addSentences(builder, sentenceExtractor, section(line, lineNum, valueStart, reader)); } builder.setPreprocessorRules(reader.getPreprocessorRules()); } catch (IOException e) { throw new RedPenException(e); } return builder.build(); }  @Override Document parse(InputStream inputStream, Optional<String> fileName, SentenceExtractor sentenceExtractor, RedPenTokenizer tokenizer); }
PropertiesParser extends BaseDocumentParser { @Override public Document parse(InputStream inputStream, Optional<String> fileName, SentenceExtractor sentenceExtractor, RedPenTokenizer tokenizer) throws RedPenException { Document.DocumentBuilder builder = Document.builder(tokenizer); fileName.ifPresent(builder::setFileName); try (PreprocessingReader reader = createReader(inputStream)) { String line; AtomicInteger lineNum = new AtomicInteger(0); while ((line = reader.readLine()) != null) { lineNum.incrementAndGet(); int keyStart = skipWhitespace(line, 0); if (keyStart == line.length()) continue; int valueStart = valueOffset(line, keyStart); addSentences(builder, sentenceExtractor, section(line, lineNum, valueStart, reader)); } builder.setPreprocessorRules(reader.getPreprocessorRules()); } catch (IOException e) { throw new RedPenException(e); } return builder.build(); }  @Override Document parse(InputStream inputStream, Optional<String> fileName, SentenceExtractor sentenceExtractor, RedPenTokenizer tokenizer);  }