Add extract_acronym
This commit is contained in:
@@ -7,3 +7,5 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = {version = "3.1.17", features = ["derive"]}
|
clap = {version = "3.1.17", features = ["derive"]}
|
||||||
|
regex = "1.5"
|
||||||
|
lazy_static = "1.4.0"
|
16
src/main.rs
16
src/main.rs
@@ -1,6 +1,8 @@
|
|||||||
use std::fs::{File, read_to_string};
|
use std::fs::{File, read_to_string};
|
||||||
use std::io::{BufWriter, Error, Write};
|
use std::io::{BufWriter, Error, Write};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
@@ -33,6 +35,19 @@ fn sort_range(lowerbound: usize, upperbound: usize, list: &mut Vec<&str>) {
|
|||||||
list[lowerbound..upperbound].sort_unstable();
|
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
|
/// Sorts the acronym block of a .tex file
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
@@ -43,3 +58,4 @@ struct Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user