outText function
Output the given text to the generated Dart file. It will generate something like the following to the Dart file:
response.write("$text");
Of course, it will escape the text properly if necessary.
Implementation
void outText(TagContext tc, String text, [int? line]) {
if (text.isEmpty)
return; //nothing to do
tc.write('\n${tc.pre}response.write("""');
for (int i = 0, len = text.length; i < len; ++i) {
final cc = text.codeUnitAt(i);
if (i == 0 && cc == $lf) {
tc.write('\n'); //first linefeed is ignored, so we have add one more
} else if (cc == $double_quote) {
if (i == len - 1) { //end with "
tc.write('\\');
} else if (i + 2 < len && text.codeUnitAt(i + 1) == $double_quote
&& text.codeUnitAt(i + 2) == $double_quote) {
tc.write('""\\');
i += 2;
}
} else if (cc == $backslash || cc == $$) {
tc.write('\\');
}
tc.writeCharCode(cc);
}
tc.writeln('""");${tc.getLineNumberComment(line)}');
}