escapeSingleQuoteString function

String? escapeSingleQuoteString(
  1. String? input,
  2. bool escapeDollar
)

Implementation

String? escapeSingleQuoteString(String? input, bool escapeDollar) {
  if (input == null) {
    return null;
  }
  var body = input.replaceAllMapped(_singleQuoteEscape, (match) {
    if (match[0] == '\$') {
      return escapeDollar ? '\\\$' : '\$';
    } else if (match[0] == '\n') {
      return '\\n';
    } else if (match[0] == '\r') {
      return '\\r';
    } else {
      return '\\${match[0]}';
    }
  });
  return "'$body'";
}