rustyphoenixlecture 1.7.2

This project aims to provide a simple a powerfull lecture compilation to generate html web sites
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/

use std::path::PathBuf;

///Find the common start of two path
/// # Parameters
/// - `absolute_input_file` : absolute path to the input file
/// - `absolute_output_dir` : absolute path to the output directory
/// # Returns
/// Relative path of the absolute_input_file without the common prefix of absolute_output_dir
pub fn remove_common_start(absolute_input_file: &PathBuf, absolute_output_dir: &PathBuf) -> PathBuf{
	let iter_parsed_file = absolute_input_file.components();
	let mut iter_output_ressource = absolute_output_dir.components();
	let mut component_output_ressource = iter_output_ressource.next();
	let mut remaining_path = PathBuf::from("");
	for component_parsed_file in iter_parsed_file {
		if component_output_ressource != None {
			if component_parsed_file != component_output_ressource.unwrap() {
				remaining_path = remaining_path.join(component_parsed_file);
				component_output_ressource = None;
			}else{
				component_output_ressource = iter_output_ressource.next();
			}
		}else{
			remaining_path = remaining_path.join(component_parsed_file);
		}
	}
	return remaining_path;
}


#[cfg(test)]
mod tests{
	use super::*;
	
	///Test the remove_common_start
	#[test]
	fn test_remove_common_start(){
		assert_eq!(remove_common_start(&PathBuf::from("/home/shadok/tweety.png"), &PathBuf::from("/home/website")), PathBuf::from("shadok/tweety.png"));
	}
}