Skip to content

Commit

Permalink
init: ported Replace_{String,Unicode} primitive function
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Galyna, Cory <[email protected]>
Co-authored-by: (Holloway) Chew, Kean Ho <[email protected]>
Signed-off-by: (Holloway) Chew, Kean Ho <[email protected]>
  • Loading branch information
4 people committed Nov 24, 2024
1 parent 0e986e6 commit fb50e28
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 0 deletions.
42 changes: 42 additions & 0 deletions init/services/HestiaKERNEL/String/Replace_String.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# 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
}
44 changes: 44 additions & 0 deletions init/services/HestiaKERNEL/String/Replace_String.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# 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 $?
}
44 changes: 44 additions & 0 deletions init/services/HestiaKERNEL/Unicode/Replace_Unicode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# 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
}
}
36 changes: 36 additions & 0 deletions init/services/HestiaKERNEL/Unicode/Replace_Unicode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# 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 $?
}
4 changes: 4 additions & 0 deletions init/services/HestiaKERNEL/Vanilla.sh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions init/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" '' '')|"
Expand Down
16 changes: 16 additions & 0 deletions init/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" "" "")"
Expand Down

0 comments on commit fb50e28

Please sign in to comment.