From a2c6012e725b27e627f8b63c3b529420bf258c78 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Tue, 17 Dec 2024 07:23:19 +0900 Subject: [PATCH] Import bash_version() Co-authored-by: Huw Walters --- src/std/text.ab | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/std/text.ab b/src/std/text.ab index 7ae297cf..d43d000b 100644 --- a/src/std/text.ab +++ b/src/std/text.ab @@ -1,11 +1,17 @@ +// Replace this with builtin if/when we get around to writing one. +#[allow_absurd_cast] +fun bash_version(): Num { + let major = trust $ echo "\$\{BASH_VERSINFO[0]}" $ as Num + let minor = trust $ echo "\$\{BASH_VERSINFO[1]}" $ as Num + return (major * 100) + minor +} + /// Replaces all occurrences of a pattern in the content with the provided replace text. #[allow_absurd_cast] pub fun replace(source, search, replace) { search = trust $ echo \$\{{nameof search}//\\\\/\\\\\\\\} $ // TODO: Revisit after https://github.com/amber-lang/amber/issues/622 - const bash_major = trust $ echo \"\$\{BASH_VERSINFO[0]}\" $ as Num - const bash_minor = trust $ echo \"\$\{BASH_VERSINFO[1]}\" $ as Num - if bash_major > 5 or (bash_major == 5 and bash_minor > 1) { + if bash_version() >= 502 { replace = trust $ echo \$\{{nameof replace}//\\\\/\\\\\\\\} $ } else { replace = trust $ echo \$\{{nameof replace}//\\\\/\\\\} $