refactor(scala): parse version w/o regex (#2574)

This commit is contained in:
Dario Vladović 2021-04-15 08:47:00 +02:00 committed by GitHub
parent 49f5b9c439
commit f765ca3b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -3,10 +3,6 @@ use crate::formatter::StringFormatter;
use super::{Context, Module, RootModuleConfig};
use regex::Regex;
const SCALA_VERSION_PATTERN: &str = "version[\\s](?P<version>[^\\s]+)";
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("scala");
let config: ScalaConfig = ScalaConfig::try_load(module.config);
@ -65,9 +61,11 @@ fn get_scala_version(context: &Context) -> Option<String> {
}
fn parse_scala_version(scala_version: &str) -> Option<String> {
let re = Regex::new(SCALA_VERSION_PATTERN).ok()?;
let captures = re.captures(scala_version)?;
let version = &captures["version"];
let version = scala_version
// split into ["Scala", "compiler", "version", "2.13.5", "--", ...]
.split_whitespace()
// take "2.13.5"
.nth(3)?;
Some(format!("v{}", &version))
}