convertFancyQuotes static method

String convertFancyQuotes(
  1. String string
)

Implementation

static String convertFancyQuotes(String string) => string
    .replaceAllMapped(RegExp(r'[\u2018\u2019\u201C\u201D\u2014]'), (match) {
      switch (match.group(0)) {
        case '\u2018': // left single quote (‘)
        case '\u2019': // right single quote (’)
          return "'";
        case '\u201C': // left double quote (“)
        case '\u201D': // right double quote (”)
          return '"';
        case '\u2014': // em dash (—)
          return '-';
        default:
          return match.group(0)!;
      }
    })
    .replaceAll(r'\n', '')
    .replaceAll(r'\\\"', "<backslash&quot>")
    .replaceAll(r'\', '')
    .replaceAll(r'<backslash&quot>', r'\"');