Add extract_acronym
This commit is contained in:
16
src/main.rs
16
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 {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user