AppFlowy/frontend/appflowy_flutter/lib/util/string_extension.dart
Lucas.Xu 3db9024a2d
chore: release 0.3.1 (#3326)
* chore: update editor version

* fix: export name (with CJK) doesn't match the document name

* chore: bump version 0.3.1
2023-09-04 17:28:19 +08:00

21 lines
554 B
Dart

import 'package:flutter/material.dart';
extension EncodeString on String {
static const _specialCharacters = r'\/:*?"<>| ';
/// Encode a string to a file name.
///
/// Normalizes the string to remove special characters and replaces the "\/:*?"<>|" with underscores.
String toFileName() {
final buffer = StringBuffer();
for (final character in characters) {
if (_specialCharacters.contains(character)) {
buffer.write('_');
} else {
buffer.write(character);
}
}
return buffer.toString();
}
}