stringifyTerminal method

String stringifyTerminal(
  1. String original, [
  2. int quoteType = CHAR_SINGLE_QUOTE
])
inherited

Converts a terminal into a string, making possible to convert escape characters and quotes, so it will generate a valid string

Implementation

String stringifyTerminal(String original,
    [int quoteType = CHAR_SINGLE_QUOTE]) {
  final buffer = StringBuffer()..writeCharCode(quoteType);
  var previousCharacter = 0;
  for (final character in original.runes) {
    if (String.fromCharCode(previousCharacter) != '\\' &&
        StringHelper.isQuotes(character) &&
        character == quoteType) {
      buffer.write('\\');
    } else if (String.fromCharCode(previousCharacter) != '\\' &&
        String.fromCharCode(character) == '\\') {
      buffer.write('\\');
    }
    buffer.writeCharCode(character);
    previousCharacter = character;
  }
  buffer.writeCharCode(quoteType);
  return buffer.toString();
}