Commit bc2fab70 authored by Scott Abbey's avatar Scott Abbey

Add named pattern to prerelease handling

parent 996dd2d0
......@@ -15,8 +15,13 @@ lazy_static! {
let major = numeric_identifier;
let minor = numeric_identifier;
let patch = numeric_identifier;
let letters_numbers_dash_dot = r"[.-A-Za-z0-9]+";
// This regex does not fully parse prereleases, just extracts the whole prerelease string.
// parse_version() will parse this further.
let pre = letters_numbers_dash_dot;
let pre = r"\w+";
let regex = format!(r"^(?P<major>{})\.(?P<minor>{})\.(?P<patch>{})(:?-(?P<pre>{}))?$", major, minor, patch, pre);
println!("{}", regex);
......@@ -31,7 +36,7 @@ pub struct Version {
pub major: u64,
pub minor: u64,
pub patch: u64,
pub pre: Option<String>,
pub pre: Option<Vec<String>>,
}
pub fn parse_version(version: &str) -> Result<Version, Box<Error>> {
......@@ -40,11 +45,15 @@ pub fn parse_version(version: &str) -> Result<Version, Box<Error>> {
None => return Err(From::from("Version did not parse properly.")),
};
let pre = captures.name("pre").map(|pre| {
vec![pre.to_string()]
});
Ok(Version {
major: captures.name("major").unwrap().parse().unwrap(),
minor: captures.name("minor").unwrap().parse().unwrap(),
patch: captures.name("patch").unwrap().parse().unwrap(),
pre: captures.name("pre").map(ToString::to_string)
pre: pre,
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment