Skip to content

Commit

Permalink
Extract removing tailing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
takahi-i committed May 5, 2017
1 parent c7df668 commit 3f053e6
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions redpen-core/src/main/java/cc/redpen/parser/rest/ReSTParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,7 @@ private boolean isNormalList(TargetLine target, State state) {
line.setListLevel(1);
line.setListStart(true);
line.erase(0, spacePos+1);
while (Character.isWhitespace(line.charAt(++spacePos))) {
line.erase(spacePos, 1);
spacePos++;
}
removeWhitespaces(line, ++spacePos);
return true;
}
return false;
Expand All @@ -270,11 +267,7 @@ private boolean isDefinitionList(TargetLine target, State state) {
if (state.inList && ((line.charAt(0) == ' ' && line.charAt(1) == ' ') || (line.charAt(0) == '\t'))) {
line.setListLevel(1);
line.setListStart(true);
int spacePos = 0;
while (Character.isWhitespace(line.charAt(spacePos))) {
line.erase(spacePos, 1);
spacePos++;
}
removeWhitespaces(line, 0);
return true;
}
return false;
Expand All @@ -288,10 +281,7 @@ private boolean isDigitList(TargetLine target, State state) {
line.setListStart(true);
int dotPos = target.line.getText().indexOf(".");
line.erase(0, ++dotPos);
while (Character.isWhitespace(target.line.charAt(dotPos))) {
line.erase(dotPos, 1);
dotPos++;
}
removeWhitespaces(line, dotPos);
return true;
}
return false;
Expand Down Expand Up @@ -343,4 +333,11 @@ private void eraseInlineMarkup(Line line) {

// FIXME: inline annotation with reference_ and anonymous__ not covered yet.
}

private void removeWhitespaces(Line line, int startPosition) {
while (Character.isWhitespace(line.charAt(startPosition))) {
line.erase(startPosition, 1);
startPosition++;
}
}
}

0 comments on commit 3f053e6

Please sign in to comment.