Skip to content

Commit 7eed901

Browse files
committed
factor concat function
1 parent 581778e commit 7eed901

File tree

3 files changed

+71
-21
lines changed

3 files changed

+71
-21
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib.rs

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::collections::HashMap;
1414
use std::fs;
1515
use std::{clone::Clone, path::PathBuf};
1616

17-
1817
/// # parse_dir
1918
/// List files and directories in the targeted directory, take a `String` as
2019
/// input and return a `Vec<String>` of the entries.
@@ -23,11 +22,9 @@ pub fn parse_dir(input_path: &str) -> Paths {
2322
Paths::new(
2423
paths_dir
2524
.filter_map(|entry| {
26-
entry.ok().and_then(|e| {
27-
e.path()
28-
.file_name()
29-
.map(PathBuf::from)
30-
})
25+
entry
26+
.ok()
27+
.and_then(|e| e.path().file_name().map(PathBuf::from))
3128
})
3229
.collect::<Vec<PathBuf>>(),
3330
)
@@ -42,11 +39,9 @@ pub fn recursive_dir(input_path: &str) -> Paths {
4239
.sort(true)
4340
.into_iter()
4441
.filter_map(|entry| {
45-
entry.ok().and_then(|e| {
46-
e.path()
47-
.file_name()
48-
.map(PathBuf::from)
49-
})
42+
entry
43+
.ok()
44+
.and_then(|e| e.path().file_name().map(PathBuf::from))
5045
})
5146
.collect::<Vec<PathBuf>>(),
5247
)
@@ -286,13 +281,64 @@ fn test_continuity() {
286281
assert_eq!(expected, group_continuity(&source));
287282
}
288283
#[test]
289-
fn test_create_frame_string() {
290-
let source: Vec<String> = vec![
291-
"001".to_string(),
292-
"005".to_string(),
293-
"003".to_string(),
294-
"002".to_string(),
295-
];
296-
let expected: String = "1-3,5".to_string();
297-
assert_eq!(expected, create_frame_string(source));
284+
fn test_convert_vec_to_str() {
285+
let source: Vec<Vec<isize>> = vec![vec![1, 2, 3], vec![5, 6, 7], vec![11, 12], vec![45]];
286+
let expected: String = "1-3,5-7,11-12,45".to_string();
287+
assert_eq!(expected, convert_vec_to_str(source));
288+
}
289+
290+
fn concat_line(main_string: String, frame_string: String) -> String {
291+
let buf: bool = false;
292+
if buf {
293+
let from: String = String::from("#####");
294+
main_string.replace(&from, &frame_string)
295+
} else {
296+
format!("{}@{}", main_string, frame_string)
297+
}
298+
}
299+
#[test]
300+
fn test_concat_line() {
301+
let main_string: String = String::from("toto");
302+
let frame_string: String = String::from("bar");
303+
let expected: String = String::from("toto@bar");
304+
assert_eq!(expected, concat_line(main_string, frame_string));
305+
}
306+
pub fn basic(frames: Vec<String>) -> Vec<String> {
307+
let frames_dict: HashMap<String, Vec<String>> = parse_result(frames);
308+
let mut out_frames: Vec<String> = Vec::new();
309+
for (key, value) in frames_dict {
310+
if value[0] == "None" && value.len() == 1 {
311+
out_frames.push(key);
312+
} else {
313+
let i = convert_vec(value);
314+
let j = group_continuity(&i);
315+
let k = convert_vec_to_str(j);
316+
out_frames.push(concat_line(key, k));
317+
}
318+
}
319+
out_frames
320+
}
321+
322+
pub fn listing(root_path: String, frames: Vec<String>) -> Vec<String> {
323+
let re: Regex = Regex::new(r".*.exr$").unwrap();
324+
let frames_dict: HashMap<String, Vec<String>> = parse_result(frames);
325+
let mut out_frames: Vec<String> = Vec::new();
326+
for (key, value) in frames_dict {
327+
if value[0] == "None" && value.len() == 1 {
328+
out_frames.push(key);
329+
} else {
330+
let to = value.first().unwrap();
331+
let from = String::from_utf8(vec![b'#'; to.len()]).unwrap();
332+
let new_path = &key.replace(&from, to);
333+
if re.is_match(new_path) {
334+
let path = format!("{}{}", root_path, new_path);
335+
read_meta(path);
336+
};
337+
let i = convert_vec(value);
338+
let j = group_continuity(&i);
339+
let k = convert_vec_to_str(j);
340+
out_frames.push(concat_line(key, k));
341+
}
342+
}
343+
out_frames
298344
}

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ struct Args {
1313
#[arg(short, long)]
1414
recursive: bool,
1515

16+
/// Display Buf format
17+
#[arg(short, long)]
18+
buf: bool,
19+
1620
/// Path to parse
1721
#[arg(default_value_t = String::from("./"), last = true)]
1822
root: String,

0 commit comments

Comments
 (0)