Skip to content

Commit

Permalink
Fix Godot version regex parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Dec 12, 2022
1 parent 36bbd66 commit 7488b2e
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions godot-codegen/src/godot_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ pub struct GodotVersion {

pub fn parse_godot_version(version_str: &str) -> Result<GodotVersion, Box<dyn Error>> {
let regex = Regex::new(
r#"(\d+)\.(\d+)(?:\.(\d+))?\.(alpha|beta|dev|stable)[0-9]*\.(?:mono)\.(?:(?:official|custom_build)\.([a-f0-9]+)|official)"#,
r#"(\d+)\.(\d+)(?:\.(\d+))?\.(alpha|beta|dev|stable)[0-9]*\.(?:mono\.)?(?:(?:official|custom_build)\.([a-f0-9]+)|official)"#,
)?;

let caps = regex.captures(version_str).ok_or("Regex capture failed")?;

let fail = || {
format!(
"Version substring could not be matched in '{}'",
version_str
)
};
let fail = || format!("Version substring cannot be parsed: `{}`", version_str);
let caps = regex.captures(version_str).ok_or_else(fail)?;

Ok(GodotVersion {
full_string: caps.get(0).unwrap().as_str().to_string(),
Expand Down

0 comments on commit 7488b2e

Please sign in to comment.