Commit ae1b3359 authored by Scott Abbey's avatar Scott Abbey

Add basic build string handling

parent bc2fab70
......@@ -22,8 +22,24 @@ lazy_static! {
// parse_version() will parse this further.
let pre = letters_numbers_dash_dot;
let regex = format!(r"^(?P<major>{})\.(?P<minor>{})\.(?P<patch>{})(:?-(?P<pre>{}))?$", major, minor, patch, pre);
// This regex does not fully parse builds, just extracts the whole build string.
// parse_version() will parse this further.
let build = letters_numbers_dash_dot;
let regex = format!(r"^(?x) # heck yes x mode
(?P<major>{}) # major version
\. # dot
(?P<minor>{}) # minor version
\. # dot
(?P<patch>{}) # patch version
(:?-(?P<pre>{}))? # optional prerelease version
(:?\+(?P<build>{}))? # optional build metadata
$",
major,
minor,
patch,
pre,
build);
println!("{}", regex);
let regex = Regex::new(&regex);
......@@ -37,6 +53,7 @@ pub struct Version {
pub minor: u64,
pub patch: u64,
pub pre: Option<Vec<String>>,
pub build: Option<Vec<String>>,
}
pub fn parse_version(version: &str) -> Result<Version, Box<Error>> {
......@@ -49,11 +66,16 @@ pub fn parse_version(version: &str) -> Result<Version, Box<Error>> {
vec![pre.to_string()]
});
let build = captures.name("build").map(|build| {
vec![build.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: pre,
build: build,
})
}
......
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