@Test void testErrorPosition() throws RedPenException { String sampleText = "He said \"that is right\"."; Configuration configuration = Configuration.builder() .addValidatorConfig(new ValidatorConfiguration("EndOfSentence")) .build(); DocumentParser parser = DocumentParser.MARKDOWN; List<Document> documents = new ArrayList<>(); Document document = parser.parse(sampleText, new SentenceExtractor(configuration.getSymbolTable()), configuration.getTokenizer()); documents.add(document); RedPen redPen = new RedPen(configuration); List<ValidationError> errors = redPen.validate(documents).get(documents.get(0)); assertEquals(1, errors.size()); assertEquals("EndOfSentence", errors.get(0).getValidatorName()); assertEquals(new LineOffset(1, 22), errors.get(0).getStartPosition().get()); assertEquals(new LineOffset(1, 23), errors.get(0).getEndPosition().get()); }
@Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } }
EndOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } } }
EndOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } }  }
EndOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } }  @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence); }
EndOfSentenceValidator extends Validator { @Override public void validate(Sentence sentence) { String content = sentence.getContent(); if (content.length() < 2) { return; } char lastCharacter = content.charAt(content.length() - 1); char secondCharacter = content.charAt(content.length() - 2); if (lastCharacter == period || lastCharacter == questionMark || lastCharacter == exclamationMark) { if (secondCharacter == rightSingleQuotation || secondCharacter == rightDoubleQuotation) { addLocalizedErrorWithPosition(sentence, content.length() - 2, content.length() - 1, String.valueOf(secondCharacter) + lastCharacter); } } }  @Override List<String> getSupportedLanguages(); @Override void validate(Sentence sentence);  }