From f765ca3b3f616ead7b10f2410b4f6ee658c05489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20Vladovi=C4=87?= Date: Thu, 15 Apr 2021 08:47:00 +0200 Subject: [PATCH] refactor(scala): parse version w/o regex (#2574) --- src/modules/scala.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/modules/scala.rs b/src/modules/scala.rs index f02f44cc..16290aee 100644 --- a/src/modules/scala.rs +++ b/src/modules/scala.rs @@ -3,10 +3,6 @@ use crate::formatter::StringFormatter; use super::{Context, Module, RootModuleConfig}; -use regex::Regex; - -const SCALA_VERSION_PATTERN: &str = "version[\\s](?P[^\\s]+)"; - pub fn module<'a>(context: &'a Context) -> Option> { 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 { } fn parse_scala_version(scala_version: &str) -> Option { - 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)) }