words method
Read count
words from the specified file
If startWithLorem is set to true
, the first words will be replaced
The words are not delimited
Implementation
String words([int count = 100]) {
final List<String> result = [];
while (result.length < count) {
String line = _lines.elementAt(Random().nextInt(_lines.length));
// trim and remove empty words
Iterable<String> words =
line.split(" ").map((e) => e.trim()).where((word) => word.isNotEmpty);
if (result.length + words.length > count) {
result.addAll(words.take(count - result.length));
} else {
result.addAll(words);
}
}
/// replace as many first chars as possible with the defined lorem ones
if (startWithLorem) {
int until = result.length < _lorem.length ? result.length : _lorem.length;
result.replaceRange(
0,
until,
_lorem.take(until),
);
}
return _prepString(result.join(" "), delimit: false);
}