replaceReadmeSection function

String replaceReadmeSection(
  1. String text,
  2. String section
)

Replaces the block between kReadmeStart and kReadmeEnd in text with section; appends the section when the markers are absent.

Implementation

String replaceReadmeSection(String text, String section) {
  final s = text.indexOf(kReadmeStart);
  final e = text.indexOf(kReadmeEnd);
  return (s >= 0 && e > s)
      ? text.replaceRange(s, e + kReadmeEnd.length, section)
      : '${text.trimRight()}\n\n$section\n';
}