Skip to content

Commit

Permalink
Issue #14689: Fix check (ignore, will merge with other commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
patchwork01 committed Mar 28, 2024
1 parent 6cfadae commit 2afe320
Showing 1 changed file with 18 additions and 18 deletions.
Expand Up @@ -589,17 +589,10 @@ private static String getFirstSentence(DetailNode ast, String period) {
boolean foundPeriod = false;
while (!stack.isEmpty()) {
final DetailNode node = stack.pop();
if (node.getChildren().length == 0) {
final String text = node.getText();
final int periodIndex = findEndingPeriod(text, period);
if (periodIndex >= 0) {
foundPeriod = true;
result.append(text, 0, periodIndex);
break;
}
else {
result.append(text);
}
if (node.getChildren().length == 0
&& appendUpToPeriod(node.getText(), period, result)) {
foundPeriod = true;
break;
}
// Pushing last child first means it will be processed last
for (int childIndex = node.getChildren().length - 1; childIndex >= 0; childIndex--) {
Expand All @@ -613,26 +606,33 @@ private static String getFirstSentence(DetailNode ast, String period) {
}

/**
* Find position of an ending period in the text. Ignores any period not followed by
* whitespace.
* Find a period in the given text. If one is present, append the text before the period to the
* result. If no period is present, append the whole string to the result.
*
* @param text text to search
* @param period period character
* @return position of period character, or -1 if there is no ending period
* @param text string to append to result
* @param period period character to find
* @param result builder to append to
* @return true if a period was found, false otherwise
*/
private static int findEndingPeriod(String text, String period) {
private static boolean appendUpToPeriod(String text, String period, StringBuilder result) {
int periodIndex = text.indexOf(period);
boolean foundPeriod = false;
while (periodIndex >= 0) {
final int afterPeriodIndex = periodIndex + period.length();
if (afterPeriodIndex >= text.length()
|| Character.isWhitespace(text.charAt(afterPeriodIndex))) {
result.append(text, 0, periodIndex);
foundPeriod = true;
break;
}
else {
periodIndex = text.indexOf(period, afterPeriodIndex);
}
}
return periodIndex;
if (!foundPeriod) {
result.append(text);
}
return foundPeriod;
}

}

0 comments on commit 2afe320

Please sign in to comment.