mirror of
https://github.com/localsend/localsend.git
synced 2025-05-17 14:36:16 +08:00
@ -1,7 +1,7 @@
|
||||
import 'package:common/model/file_type.dart';
|
||||
|
||||
/// Matches myFile-123 -> 123
|
||||
final _fileNumberRegex = RegExp(r'^(.*)(?:-(\d+))$');
|
||||
/// Matches myFile (123) -> "myFile", " (123)"
|
||||
final _fileNumberRegex = RegExp(r'^(.*)(?:(\s\(\d+\)))$');
|
||||
|
||||
extension FilePathStringExt on String {
|
||||
String get extension {
|
||||
@ -43,9 +43,9 @@ extension FilePathStringExt on String {
|
||||
|
||||
final match = _fileNumberRegex.firstMatch(fileName);
|
||||
if (match != null) {
|
||||
return '${match.group(1)}-$count'.withExtension(extension);
|
||||
return '${match.group(1)} ($count)'.withExtension(extension);
|
||||
} else {
|
||||
return '$fileName-$count'.withExtension(extension);
|
||||
return '$fileName ($count)'.withExtension(extension);
|
||||
}
|
||||
}
|
||||
|
||||
|
9
app/test/unit/util/file_path_helper_test.dart
Normal file
9
app/test/unit/util/file_path_helper_test.dart
Normal file
@ -0,0 +1,9 @@
|
||||
import 'package:localsend_app/util/file_path_helper.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('fileName with counter', () async {
|
||||
expect('myFile'.withCount(1), 'myFile (1)');
|
||||
expect('myFile (1)'.withCount(2), 'myFile (2)');
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user