mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
21 lines
554 B
Dart
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();
|
||
|
}
|
||
|
}
|