Skip to content

Commit 7aeda11

Browse files
committed
add the buf option
1 parent 664192d commit 7aeda11

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

benches/big.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use framels::{basic_listing, parse_dir};
33

44
fn parse_and_run() {
55
let paths: Vec<String> = parse_dir("./samples/big".to_string());
6-
let _results: Vec<String> = basic_listing(paths);
6+
let _results: Vec<String> = basic_listing(paths, false);
77
}
88

99
fn criterion_benchmark(c: &mut Criterion) {

benches/mega.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn get_data_set() -> Vec<String> {
1414
}
1515

1616
fn parse_and_run() {
17-
let _results: Vec<String> = basic_listing(get_data_set());
17+
let _results: Vec<String> = basic_listing(get_data_set(), false);
1818
}
1919

2020
fn criterion_benchmark(c: &mut Criterion) {

benches/small.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use framels::{basic_listing, parse_dir};
33

44
fn parse_and_run() {
55
let paths: Vec<String> = parse_dir("./samples/small/".to_string());
6-
let _results: Vec<String> = basic_listing(paths);
6+
let _results: Vec<String> = basic_listing(paths, false);
77
}
88

99
fn criterion_benchmark(c: &mut Criterion) {

src/lib.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ fn test_create_frame_string() {
207207
assert_eq!(expected, create_frame_string(source));
208208
}
209209
#[allow(dead_code)]
210-
fn concat_line(main_string: String, frame_string: String) -> String {
211-
let buf: bool = false;
210+
/// This function is intend to keep padding in the string lile:
211+
/// aa.[0035-0036].exr
212+
fn concat_line(main_string: String, frame_string: String, padding: String, buf:bool) -> String {
212213
if buf {
213-
let from: String = String::from("#####");
214+
let from: String = String::from(padding);
214215
main_string.replace(&from, &frame_string)
215216
} else {
216217
format!("{}@{}", main_string, frame_string)
@@ -221,8 +222,16 @@ fn test_concat_line() {
221222
let main_string: String = String::from("toto");
222223
let frame_string: String = String::from("bar");
223224
let expected: String = String::from("toto@bar");
224-
assert_eq!(expected, concat_line(main_string, frame_string));
225+
assert_eq!(expected, concat_line(main_string, frame_string,"#####".to_string(), false));
225226
}
227+
#[test]
228+
fn test_buf_concat_line() {
229+
let main_string: String = String::from("toto.#####.exr");
230+
let frame_string: String = String::from("bar");
231+
let expected: String = String::from("toto.bar.exr");
232+
assert_eq!(expected, concat_line(main_string, frame_string,"#####".to_string(), true));
233+
}
234+
226235
/// ## Basic listing of the library
227236
/// ### Description
228237
///
@@ -232,14 +241,16 @@ fn test_concat_line() {
232241
///
233242
/// It take a `Vec<String>` of entries as an input
234243
/// - Pack the frames
235-
pub fn basic_listing(frames: Vec<String>) -> Vec<String> {
244+
pub fn basic_listing(frames: Vec<String>, buf:bool) -> Vec<String> {
236245
let frames_dict: HashMap<String, Vec<String>> = parse_result(frames);
237246
let mut out_frames: Vec<String> = Vec::new();
238247
for (key, value) in frames_dict {
239248
if value[0] == "None" && value.len() == 1 {
240249
out_frames.push(key);
241250
} else {
242-
out_frames.push(format!("{}@{}", key, create_frame_string(value)));
251+
let to =value.first().unwrap();
252+
let from = String::from_utf8(vec![b'#'; to.len()]).unwrap();
253+
out_frames.push(concat_line(key, create_frame_string(value),from,buf ));
243254
}
244255
}
245256
out_frames
@@ -264,7 +275,7 @@ fn get_exr_metada(re: &Regex, root_path: &String, path: &String) -> String {
264275
/// - Pack the frames
265276
/// - Print the metada if the sequence is an exr sequence
266277
/// - Return a Vector of path packed
267-
pub fn extended_listing(root_path: String, frames: Vec<String>) -> Vec<String> {
278+
pub fn extended_listing(root_path: String, frames: Vec<String>, buf:bool) -> Vec<String> {
268279
let re: Regex = Regex::new(r".*.exr$").unwrap();
269280
let frames_dict: HashMap<String, Vec<String>> = parse_result(frames);
270281
let mut out_frames: Vec<String> = Vec::new();
@@ -278,7 +289,7 @@ pub fn extended_listing(root_path: String, frames: Vec<String>) -> Vec<String> {
278289
let from = String::from_utf8(vec![b'#'; to.len()]).unwrap();
279290
let new_path = &key.replace(&from, to);
280291
medata.push(get_exr_metada(&re, &root_path, &new_path));
281-
out_frames.push(format!("{}@{}", key, create_frame_string(value)));
292+
out_frames.push(concat_line(key, create_frame_string(value),from,buf ));
282293
}
283294
}
284295
out_frames.append(&mut medata);

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ fn main() {
2222
let args = Args::parse();
2323
let results = if args.list {
2424
let paths: Vec<String> = parse_dir(args.path.clone());
25-
extended_listing(args.path, paths)
25+
extended_listing(args.path, paths, args.buf)
2626
} else {
2727
let paths: Vec<String> = parse_dir(args.path);
28-
basic_listing(paths)
28+
basic_listing(paths, args.buf)
2929
};
3030

3131
println!("{}", results.join("\n"))

0 commit comments

Comments
 (0)