From 4167c3e3394ff4b501aedaf590a09722befc2056 Mon Sep 17 00:00:00 2001 From: structix Date: Mon, 9 May 2022 12:24:08 +0200 Subject: [PATCH] Add extract_acronym --- Cargo.toml | 4 +++- src/main.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 244f8c8..2f12c6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"]} \ No newline at end of file +clap = {version = "3.1.17", features = ["derive"]} +regex = "1.5" +lazy_static = "1.4.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 976d142..5052546 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { } +