Skip to content

Commit

Permalink
factor concat function
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleailes committed May 14, 2023
1 parent 09ec2f8 commit 4677ec7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn extract_regex(re: &Regex, x: String) -> (String, String) {
(
x.replace(
&caps["frames"],
String::from_utf8(vec![b'*'; caps["frames"].len()])
String::from_utf8(vec![b'#'; caps["frames"].len()])
.unwrap()
.as_str(),
),
Expand All @@ -62,7 +62,7 @@ fn test_regex_simple() {
let re = get_regex();
let source: String = "RenderPass_Beauty_1_00000.exr".to_string();
let expected: (String, String) = (
"RenderPass_Beauty_1_*****.exr".to_string(),
"RenderPass_Beauty_1_#####.exr".to_string(),
"00000".to_string(),
);
assert_eq!(expected, extract_regex(&re, source))
Expand Down Expand Up @@ -102,7 +102,7 @@ fn test_parse_string() {
let vec_toto: Vec<String> = vec!["001".to_string(), "002".to_string(), "003".to_string()];
let vec_foo: Vec<String> = vec!["None".to_string()];
let expected: HashMap<String, Vec<String>> = HashMap::from([
("toto.***.tiff".to_string(), vec_toto),
("toto.###.tiff".to_string(), vec_toto),
("foo.exr".to_string(), vec_foo),
]);
assert_eq!(expected, parse_result(source));
Expand Down Expand Up @@ -161,6 +161,22 @@ fn test_convert_vec_to_str() {
assert_eq!(expected, convert_vec_to_str(source));
}

fn concat_line(main_string: String, frame_string: String) -> String {
let buf: bool = false;
if buf {
let from: String = String::from("#####");
main_string.replace(&from, &frame_string)
} else {
format!("{}@{}", main_string, frame_string)
}
}
#[test]
fn test_concat_line() {
let main_string: String = String::from("toto");
let frame_string: String = String::from("bar");
let expected: String = String::from("toto@bar");
assert_eq!(expected, concat_line(main_string, frame_string));
}
pub fn basic(frames: Vec<String>) -> Vec<String> {
let frames_dict: HashMap<String, Vec<String>> = parse_result(frames);
let mut out_frames: Vec<String> = Vec::new();
Expand All @@ -171,7 +187,7 @@ pub fn basic(frames: Vec<String>) -> Vec<String> {
let i = convert_vec(value);
let j = group_continuity(&i);
let k = convert_vec_to_str(j);
out_frames.push(format!("{}@{}", key, k));
out_frames.push(concat_line(key, k));
}
}
out_frames
Expand All @@ -186,7 +202,7 @@ pub fn listing(root_path: String, frames: Vec<String>) -> Vec<String> {
out_frames.push(key);
} else {
let to = value.first().unwrap();
let from = String::from_utf8(vec![b'*'; to.len()]).unwrap();
let from = String::from_utf8(vec![b'#'; to.len()]).unwrap();
let new_path = &key.replace(&from, to);
if re.is_match(new_path) {
let path = format!("{}{}", root_path, new_path);
Expand All @@ -195,7 +211,7 @@ pub fn listing(root_path: String, frames: Vec<String>) -> Vec<String> {
let i = convert_vec(value);
let j = group_continuity(&i);
let k = convert_vec_to_str(j);
out_frames.push(format!("{}@{}", key, k));
out_frames.push(concat_line(key, k));
}
}
out_frames
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ struct Args {
#[arg(short, long)]
list: bool,

/// Display Buf format
#[arg(short, long)]
buf: bool,

/// Path to parse
#[arg(default_value_t = String::from("./"), last = true)]
path: String,
Expand Down

0 comments on commit 4677ec7

Please sign in to comment.