From fb50e2810e12f8f53cfb3bfc28a283df5881b35e Mon Sep 17 00:00:00 2001 From: "(Holloway) Chew, Kean Ho" Date: Sun, 24 Nov 2024 13:41:49 +0800 Subject: [PATCH] init: ported Replace_{String,Unicode} primitive function Since there are a number of level 1 libraries using the string function, we have to port its primitive ones into HestiaKERNEL library. Let's do this. This patch ports Replace_{String,Unicode} primitive function into HestiaKERNEL library into init/ directory. Co-authored-by: Shuralyov, Jean Co-authored-by: Galyna, Cory Co-authored-by: (Holloway) Chew, Kean Ho Signed-off-by: (Holloway) Chew, Kean Ho --- .../HestiaKERNEL/String/Replace_String.ps1 | 42 ++++++++++++++++++ .../HestiaKERNEL/String/Replace_String.sh | 44 +++++++++++++++++++ .../HestiaKERNEL/Unicode/Replace_Unicode.ps1 | 44 +++++++++++++++++++ .../HestiaKERNEL/Unicode/Replace_Unicode.sh | 36 +++++++++++++++ init/services/HestiaKERNEL/Vanilla.sh.ps1 | 4 ++ init/start.ps1 | 13 ++++++ init/start.sh | 16 +++++++ 7 files changed, 199 insertions(+) create mode 100644 init/services/HestiaKERNEL/String/Replace_String.ps1 create mode 100644 init/services/HestiaKERNEL/String/Replace_String.sh create mode 100644 init/services/HestiaKERNEL/Unicode/Replace_Unicode.ps1 create mode 100644 init/services/HestiaKERNEL/Unicode/Replace_Unicode.sh diff --git a/init/services/HestiaKERNEL/String/Replace_String.ps1 b/init/services/HestiaKERNEL/String/Replace_String.ps1 new file mode 100644 index 0000000..aa99c81 --- /dev/null +++ b/init/services/HestiaKERNEL/String/Replace_String.ps1 @@ -0,0 +1,42 @@ +# Copyright 2024 (Holloway) Chew, Kean Ho +# +# +# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License"). +# You must comply with the license to use the content. Get the License at: +# +# https://doi.org/10.5281/zenodo.13770769 +# +# You MUST ensure any interaction with the content STRICTLY COMPLIES with +# the permissions and limitations set forth in the license. +. "${env:LIBS_HESTIA}\HestiaKERNEL\String\To_String_From_Unicode.ps1" +. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Replace_Unicode.ps1" +. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\To_Unicode_From_String.ps1" + + + + +function HestiaKERNEL-Replace-String { + param ( + [string]$___input, + [string]$___from, + [string]$___to, + [int32]$___count, + [int32]$___ignore, + [string]$___from_right + ) + + + # execute + $___content = HestiaKERNEL-To-Unicode-From-String $___input + $___chars_from = HestiaKERNEL-To-Unicode-From-String $___from + $___chars_to = HestiaKERNEL-To-Unicode-From-String $___to + $___content = HestiaKERNEL-Replace-Unicode $___content ` + $___chars_from ` + $___chars_to ` + $___count ` + $___ignore + + + # report status + return HestiaKERNEL-To-String-From-Unicode $___content +} diff --git a/init/services/HestiaKERNEL/String/Replace_String.sh b/init/services/HestiaKERNEL/String/Replace_String.sh new file mode 100644 index 0000000..0ce1639 --- /dev/null +++ b/init/services/HestiaKERNEL/String/Replace_String.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# Copyright 2024 (Holloway) Chew, Kean Ho +# +# +# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License"). +# You must comply with the license to use the content. Get the License at: +# +# https://doi.org/10.5281/zenodo.13770769 +# +# You MUST ensure any interaction with the content STRICTLY COMPLIES with +# the permissions and limitations set forth in the license. +. "${LIBS_HESTIA}/HestiaKERNEL/String/To_String_From_Unicode.sh" +. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Replace_Unicode.sh" +. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/To_Unicode_From_String.sh" + + + + +HestiaKERNEL_Replace_String() { + #___input="$1" + #___from="$2" + #___to="$3" + #___count="$4" + #___ignore="$5" + #___direction="$6" + + + # execute + ___content="$(HestiaKERNEL_To_Unicode_From_String "$1")" + ___chars_from="$(HestiaKERNEL_To_Unicode_From_String "$2")" + ___chars_to="$(HestiaKERNEL_To_Unicode_From_String "$3")" + ___content="$(HestiaKERNEL_Replace_Unicode "$___content" \ + "$___chars_from" \ + "$___chars_to" \ + "$4" \ + "$5" \ + "$6" + )" + + + # report status + printf -- "%b" "$(HestiaKERNEL_To_String_From_Unicode "$___content")" + return $? +} diff --git a/init/services/HestiaKERNEL/Unicode/Replace_Unicode.ps1 b/init/services/HestiaKERNEL/Unicode/Replace_Unicode.ps1 new file mode 100644 index 0000000..c4f63f0 --- /dev/null +++ b/init/services/HestiaKERNEL/Unicode/Replace_Unicode.ps1 @@ -0,0 +1,44 @@ +# Copyright 2024 (Holloway) Chew, Kean Ho +# +# +# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License"). +# You must comply with the license to use the content. Get the License at: +# +# https://doi.org/10.5281/zenodo.13770769 +# +# You MUST ensure any interaction with the content STRICTLY COMPLIES with +# the permissions and limitations set forth in the license. +. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Replace_Left_Unicode.ps1" +. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Replace_Right_Unicode.ps1" + + + + +function HestiaKERNEL-Replace-Unicode { + param ( + [uint32[]]$___content_unicode, + [uint32[]]$___from_unicode, + [uint32[]]$___to_unicode, + [int32]$___count, + [int32]$___ignore, + [string]$___from_right + ) + + + # execute + if ($___from_right -ne "") { + return HestiaKERNEL-Replace-Right-Unicode ` + $___content_unicode ` + $___from_unicode ` + $___to_unicode ` + $___count ` + $___ignore + } else { + return HestiaKERNEL-Replace-Left-Unicode ` + $___content_unicode ` + $___from_unicode ` + $___to_unicode ` + $___count ` + $___ignore + } +} diff --git a/init/services/HestiaKERNEL/Unicode/Replace_Unicode.sh b/init/services/HestiaKERNEL/Unicode/Replace_Unicode.sh new file mode 100644 index 0000000..2ff28d6 --- /dev/null +++ b/init/services/HestiaKERNEL/Unicode/Replace_Unicode.sh @@ -0,0 +1,36 @@ +# Copyright 2024 (Holloway) Chew, Kean Ho +# +# +# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License"). +# You must comply with the license to use the content. Get the License at: +# +# https://doi.org/10.5281/zenodo.13770769 +# +# You MUST ensure any interaction with the content STRICTLY COMPLIES with +# the permissions and limitations set forth in the license. +. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Replace_Left_Unicode.sh" +. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Replace_Right_Unicode.sh" + + + + +HestiaKERNEL_Replace_Unicode() { + #___content_unicode="$1" + #___from_unicode="$2" + #___to_unicode="$3" + #___count="$4" + #___ignore="$5" + #___from_right="$6" + + + # execute + if [ ! "$6" = "" ]; then + printf -- "%b" "$(HestiaKERNEL_Replace_Right_Unicode "$1" "$2" "$3" "$4" "$5")" + else + printf -- "%b" "$(HestiaKERNEL_Replace_Left_Unicode "$1" "$2" "$3" "$4" "$5")" + fi + + + # report status + return $? +} diff --git a/init/services/HestiaKERNEL/Vanilla.sh.ps1 b/init/services/HestiaKERNEL/Vanilla.sh.ps1 index f38afb2..b71abcc 100644 --- a/init/services/HestiaKERNEL/Vanilla.sh.ps1 +++ b/init/services/HestiaKERNEL/Vanilla.sh.ps1 @@ -52,6 +52,7 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null . "${env:LIBS_HESTIA}\HestiaKERNEL\String\Is_Whitespace_String.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\String\Replace_Left_String.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\String\Replace_Right_String.ps1" +. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Replace_String.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\String\Scan_Any_Left_String.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\String\Scan_Any_Right_String.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\String\Scan_Any_String.ps1" @@ -84,6 +85,7 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null . "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Is_Whitespace_Unicode.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Replace_Left_Unicode.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Replace_Right_Unicode.ps1" +. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Replace_Unicode.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Scan_Any_Left_Unicode.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Scan_Any_Right_Unicode.ps1" . "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Scan_Any_Unicode.ps1" @@ -141,6 +143,7 @@ RUN_AS_POWERSHELL . "${LIBS_HESTIA}/HestiaKERNEL/String/Is_Whitespace_String.sh" . "${LIBS_HESTIA}/HestiaKERNEL/String/Replace_Left_String.sh" . "${LIBS_HESTIA}/HestiaKERNEL/String/Replace_Right_String.sh" +. "${LIBS_HESTIA}/HestiaKERNEL/String/Replace_String.sh" . "${LIBS_HESTIA}/HestiaKERNEL/String/Scan_Any_Left_String.sh" . "${LIBS_HESTIA}/HestiaKERNEL/String/Scan_Any_Right_String.sh" . "${LIBS_HESTIA}/HestiaKERNEL/String/Scan_Any_String.sh" @@ -173,6 +176,7 @@ RUN_AS_POWERSHELL . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Is_Whitespace_Unicode.sh" . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Replace_Left_Unicode.sh" . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Replace_Right_Unicode.sh" +. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Replace_Unicode.sh" . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Scan_Any_Left_Unicode.sh" . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Scan_Any_Right_Unicode.sh" . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Scan_Any_Unicode.sh" diff --git a/init/start.ps1 b/init/start.ps1 index c40d3ee..3b6e12b 100644 --- a/init/start.ps1 +++ b/init/start.ps1 @@ -112,6 +112,19 @@ ${env:LIBS_HESTIA} = "${env:LIBS_UPSCALER}\services" . "${env:LIBS_UPSCALER}\services\i18n\report-success.ps1" ### TEST ZONE +Write-Host "---- Replace-String ----" +Write-Host "|$(HestiaKERNEL-Replace-String "e你feeeff你你aerg aegE你F" ` + "a" ` + "z" ` + "1" ` + "-1" ` + "right")|" +Write-Host "|$(HestiaKERNEL-Replace-String "e你feeeff你你aerg aegE你F" ` + "a" ` + "z" ` + "1" ` + "-1")|" + Write-Host "---- Replace-Right-String ----" . "${env:LIBS_HESTIA}\HestiaKERNEL\String\Replace_Right_String.ps1" Write-Host "|$(HestiaKERNEL-Replace-Right-String "e你feeeff你你aerg aegE你F" '' '')|" diff --git a/init/start.sh b/init/start.sh index 6d34245..66300a6 100644 --- a/init/start.sh +++ b/init/start.sh @@ -102,6 +102,22 @@ LIBS_HESTIA="${LIBS_UPSCALER}/services" . "${LIBS_UPSCALER}/services/i18n/report-success.sh" ### TEST ZONE +1>&2 printf -- "---- Replace_String ----\n" +. "${LIBS_HESTIA}/HestiaKERNEL/String/Replace_String.sh" +1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Replace_String "e你feeeff你你aerg aegE你F" \ + "a" \ + "z" \ + "1" \ + "-1" \ + "right" \ + )" +1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Replace_String "e你feeeff你你aerg aegE你F" \ + "a" \ + "z" \ + "1" \ + "-1" \ + )" + 1>&2 printf -- "---- Replace_Right_String ----\n" . "${LIBS_HESTIA}/HestiaKERNEL/String/Replace_Right_String.sh" 1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Replace_Right_String "e你feeeff你你aerg aegE你F" "" "")"