collapseFrom method
Replaces each group of consecutive matched characters in sequence
with the specified replacement.
Implementation
String collapseFrom(String sequence, String replacement) {
final buffer = StringBuffer();
final iterator = _runeIteratorAt(sequence, 0);
while (iterator.moveNext()) {
if (match(iterator.current)) {
while (iterator.moveNext() && match(iterator.current)) {}
buffer.write(replacement);
iterator.movePrevious();
} else {
buffer.writeCharCode(iterator.current);
}
}
return buffer.toString();
}