safeName function

String safeName(
  1. String name
)

Implementation

String safeName(String name) {
  var trimmed = name
      .trim()
      .replaceAll(RegExp(r'[^a-zA-Z0-9$]'), '_')
      .replaceAll(RegExp('_{2,}'), '_');
  if (dartKeywords.contains(trimmed)) {
    trimmed = '$trimmed\$';
  }
  return trimmed;
}