toConfigString method

  1. @override
String toConfigString()
override

Format this value as it would appear in an i3 config file.

Implementation

@override
String toConfigString() {
  if (!value.contains(delimiter)) {
    return '$delimiter$value$delimiter';
  }
  // Auto-switch to the alternate delimiter if the content contains
  // the current one but not the alternate.
  final alt = delimiter == '"""' ? "'''" : '"""';
  if (!value.contains(alt)) {
    return '$alt$value$alt';
  }
  // Both delimiters present in content — fall back to single-quoted.
  return "'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'";
}