rewriteValues function
yamlText with every edit's block scalar body replaced.
Throws YamlRewriteException when a value is not a |2- block scalar
written in the encoder's shape.
Implementation
String rewriteValues(String yamlText, List<ValueEdit> edits) {
final lines = yamlText.split('\n');
final ordered = [...edits]
..sort((a, b) => b.location.keyLine.compareTo(a.location.keyLine));
for (final edit in ordered) {
final loc = edit.location;
_checkShape(lines, loc);
final oldBody = blockBody(loc.value, loc.keyColumn);
lines.replaceRange(
loc.keyLine + 1,
loc.keyLine + 1 + oldBody.length,
blockBody(edit.newValue, loc.keyColumn),
);
}
return lines.join('\n');
}