File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,12 @@ use std::fs;
3
3
use std:: fs:: File ;
4
4
use std:: io:: Write ;
5
5
6
+ fn file_to_hyphen ( name : & String ) -> String {
7
+ return String :: from ( name. replace ( "_" , "-" ) . replace ( " " , "-" ) . replace ( "." , "-" ) ) ;
8
+ }
9
+
6
10
pub fn write_metadata ( data : OutputMetadata ) {
7
- let directory = data. title . replace ( "_" , "-" ) . replace ( " " , "-" ) . replace ( "." , "-" ) ;
11
+ let directory = file_to_hyphen ( & data. title ) ;
8
12
9
13
if !fs:: metadata ( & directory) . is_ok ( ) {
10
14
fs:: create_dir ( & directory) . unwrap ( ) ;
@@ -15,3 +19,9 @@ pub fn write_metadata(data: OutputMetadata) {
15
19
let mut file = File :: create ( outpath) . unwrap ( ) ;
16
20
file. write_all ( json. as_bytes ( ) ) . unwrap ( ) ;
17
21
}
22
+
23
+ #[ test]
24
+ fn file_to_hyphen_test ( ) {
25
+ let result = file_to_hyphen ( & "2022.04.06.name with space.mp4" . to_string ( ) ) ;
26
+ assert_eq ! ( result, "2022-04-06-name-with-space-mp4" ) ;
27
+ }
You can’t perform that action at this time.
0 commit comments