paragraphs method
Read count
paragraphs from the specified file
If startWithLorem is set to true
, the first words will be replaced
The paragraphs are delimited using a random of the specified sentenceDelimiters
Implementation
String paragraphs([int count = 3]) {
final List<String> result = [];
String curParagraph = "";
String lastLine = "";
while (result.length < count) {
String line = _lines.elementAt(Random().nextInt(_lines.length)).trim();
// if we've hit the end of a paragraph
if (lastLine.length > 1 && line.isEmpty /*line == "\n"*/) {
result.add(_prepString(curParagraph));
curParagraph = "";
} else if (line.length > 1) {
// if we're still building the current paragraph
/// replace as many first words of the paragraph as possible with the defined lorem ones, but only if this is the first paragraph
if (startWithLorem && result.isEmpty && curParagraph.isEmpty) {
List<String> firstWords = line.split(' ');
firstWords.replaceRange(
0,
line.length < _lorem.length ? line.length : _lorem.length,
_lorem,
);
line = firstWords.join(" ");
}
curParagraph += line;
}
lastLine = line;
}
return result.join("\n\n");
}