Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not require after space if it is at the end of sentence #570

Merged
merged 1 commit into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

import java.util.Set;

import static java.lang.Character.isLetterOrDigit;
import static java.lang.Character.isWhitespace;

/**
* Validate symbol has before and after symbols. Needed spaces is depend on
* the symbol and defined in DVCharacterTable.
Expand All @@ -51,14 +54,12 @@ private ValidationError validateSymbol(Sentence sentence, SymbolType symbolType)
if (position != -1) {
String key = "";

if (position > 0 && symbol.isNeedBeforeSpace()
&& !Character.isWhitespace(sentenceStr.charAt(position - 1))) {
if (position > 0 && symbol.isNeedBeforeSpace() && !isWhitespace(sentenceStr.charAt(position - 1))) {
key = "Before";
}

if (position < sentenceStr.length() - 1
&& symbol.isNeedAfterSpace()
&& !Character.isWhitespace(sentenceStr.charAt(position + 1))) {
if (position < sentenceStr.length() - 1 && symbol.isNeedAfterSpace()
&& !isWhitespace(sentenceStr.charAt(position + 1)) && isLetterOrDigit(sentenceStr.charAt(position + 1))) {
key += "After";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ public void testNeedAfterSpace() throws RedPenException {
assertEquals(10, errors.get(document).get(0).getStartPosition().get().offset);
}

@Test
public void testDoNotNeedAfterSpaceAtTheEndOfSentence() throws RedPenException {
Document document = prepareSimpleDocument("Hello (world).");

config = Configuration.builder()
.addValidatorConfig(new ValidatorConfiguration("SymbolWithSpace"))
.addSymbol(new Symbol(RIGHT_PARENTHESIS, ')', "", false, true))
.build();

RedPen redPen = new RedPen(config);
Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
assertEquals(0, errors.get(document).size());
}

@Test
public void testNeedBeforeSpace() throws RedPenException {
Document document = prepareSimpleDocument("I like her(Nancy) very much.");
Expand Down