Add extract_acronym

This commit is contained in:
2022-05-09 12:24:08 +02:00
parent 8309272f1c
commit 4167c3e339
2 changed files with 19 additions and 1 deletions

View File

@@ -6,4 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = {version = "3.1.17", features = ["derive"]}
clap = {version = "3.1.17", features = ["derive"]}
regex = "1.5"
lazy_static = "1.4.0"

View File

@@ -1,6 +1,8 @@
use std::fs::{File, read_to_string};
use std::io::{BufWriter, Error, Write};
use clap::Parser;
use lazy_static::lazy_static;
use regex::Regex;
fn main() -> Result<(), Error> {
let args = Args::parse();
@@ -33,6 +35,19 @@ fn sort_range(lowerbound: usize, upperbound: usize, list: &mut Vec<&str>) {
list[lowerbound..upperbound].sort_unstable();
}
fn extract_acronym(line: &str) -> Option<(&str, &str, &str)> {
lazy_static! {
static ref RE: Regex = Regex::new(r"\{(\w+)\}\[(\w+)\]\{(.+)\}").unwrap();
}
let caps = RE.captures(line);
match caps {
Some(c) => Some((c.get(1).unwrap().as_str(),
c.get(2).unwrap().as_str(),
c.get(3).unwrap().as_str())),
_ => None
}
}
/// Sorts the acronym block of a .tex file
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
@@ -43,3 +58,4 @@ struct Args {
}