Search in sources :

Example 1 with VerseEnd

use of biblemulticonverter.format.paratext.ParatextCharacterContent.VerseEnd in project BibleMultiConverter by schierlm.

the class ParatextBook method fixTrailingWhitespace.

/**
 * Before converting to non-Paratext format, remove (unformatted) whitespace
 * at the end of a verse. Also move whitespace at the end of character
 * content outside of it. This can be introduced by importing USX2 bibles.
 * The whitespace should remain when converting to other Paratext formats,
 * therefore only strip it when converting to non-Paratext formats.
 */
public void fixTrailingWhitespace() {
    boolean seenVerseEnd = false;
    for (int i = content.size() - 1; i >= 0; i--) {
        if (content.get(i) instanceof ParatextCharacterContent) {
            ParatextCharacterContent cc = (ParatextCharacterContent) content.get(i);
            fixTrailingWhitespace(cc);
            for (int j = cc.getContent().size() - 1; j >= 0; j--) {
                if (seenVerseEnd && cc.getContent().get(j) instanceof Text) {
                    Text oldText = (Text) cc.getContent().get(j);
                    if (oldText.getChars().matches(" +")) {
                        cc.getContent().remove(j);
                    } else {
                        cc.getContent().set(j, Text.from(oldText.getChars().replaceFirst(" +$", "")));
                    }
                }
                seenVerseEnd = j < cc.getContent().size() && (cc.getContent().get(j) instanceof VerseEnd);
            }
        } else {
            seenVerseEnd = content.get(i) instanceof TableCellStart;
        }
    }
}
Also used : VerseEnd(biblemulticonverter.format.paratext.ParatextCharacterContent.VerseEnd) Text(biblemulticonverter.format.paratext.ParatextCharacterContent.Text)

Aggregations

Text (biblemulticonverter.format.paratext.ParatextCharacterContent.Text)1 VerseEnd (biblemulticonverter.format.paratext.ParatextCharacterContent.VerseEnd)1