28 lines
983 B
Rust
28 lines
983 B
Rust
use std::fs::File;
|
|
use std::io::{BufReader, BufRead};
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
let fantoir_path = std::env::args().nth(1).unwrap();
|
|
let file = match File::open(&fantoir_path) {
|
|
Err(err) => panic!("Cannot read file {}: {}", fantoir_path, err),
|
|
Ok(file) => file,
|
|
};
|
|
let reader = BufReader::new(file);
|
|
println!("full_insee;rivoli_with_key;libelle");
|
|
for line in reader.lines() {
|
|
let l = line.unwrap();
|
|
if l.chars().nth(3) == Some(' ') {
|
|
// Enregistrement Département
|
|
} else if l.chars().nth(6) == Some(' ') {
|
|
// Enregistrement Commune
|
|
} else {
|
|
let mut full_insee = String::from(l.get(0..2).unwrap());
|
|
full_insee.push_str(l.get(3..6).unwrap());
|
|
let rivoli_with_key = l.get(6..11).unwrap();
|
|
let libelle = l.get(15..41).unwrap();
|
|
println!("{};{};{}", full_insee, rivoli_with_key, libelle);
|
|
}
|
|
};
|
|
Ok(())
|
|
}
|