From 5f116094bff0367ad01ca0d6330d27af64947fc2 Mon Sep 17 00:00:00 2001 From: "(Holloway) Chew, Kean Ho" Date: Mon, 11 Nov 2024 11:34:48 +0800 Subject: [PATCH] init: backported changes to Trim_Suffix_* primitive functions There were some new optimization discovered when implementing Index_Right_{String,Unicode} functions. Hence, let's backport those changes back to its predecessor Trim_Suffix_{String,Unicode}. This patch backports changes to Trim_Suffix_{String,Unicode} primitive functions in 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/Index_Right_String.sh | 1 - .../String/Trim_Suffix_String.ps1 | 21 ++----------- .../HestiaKERNEL/String/Trim_Suffix_String.sh | 30 ++----------------- .../Unicode/Trim_Suffix_Unicode.ps1 | 11 ++++--- .../Unicode/Trim_Suffix_Unicode.sh | 16 +++++----- init/start.ps1 | 8 ++--- 6 files changed, 22 insertions(+), 65 deletions(-) diff --git a/init/services/HestiaKERNEL/String/Index_Right_String.sh b/init/services/HestiaKERNEL/String/Index_Right_String.sh index 42fa3db..b050dc5 100644 --- a/init/services/HestiaKERNEL/String/Index_Right_String.sh +++ b/init/services/HestiaKERNEL/String/Index_Right_String.sh @@ -9,7 +9,6 @@ # # You MUST ensure any interaction with the content STRICTLY COMPLIES with # the permissions and limitations set forth in the license. -. "${LIBS_HESTIA}/HestiaKERNEL/Errors/Error_Codes.sh" . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Index_Right_Unicode.sh" . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/To_Unicode_From_String.sh" diff --git a/init/services/HestiaKERNEL/String/Trim_Suffix_String.ps1 b/init/services/HestiaKERNEL/String/Trim_Suffix_String.ps1 index 8d7472a..89b863d 100644 --- a/init/services/HestiaKERNEL/String/Trim_Suffix_String.ps1 +++ b/init/services/HestiaKERNEL/String/Trim_Suffix_String.ps1 @@ -18,30 +18,13 @@ function HestiaKERNEL-Trim-Suffix-String { param ( [string]$___input, - [string]$___suffix + [string]$___target ) - # validate input - if ( - ($___input -eq "") -or - ($___suffix -eq "") - ) { - return $___input - } - - # execute $___content = HestiaKERNEL-To-Unicode-From-String $___input - if ($___content.Length -eq 0) { - return $___input - } - - $___chars = HestiaKERNEL-To-Unicode-From-String $___suffix - if ($___chars.Length -eq 0) { - return $___input - } - + $___chars = HestiaKERNEL-To-Unicode-From-String $___target $___content = HestiaKERNEL-Trim-Suffix-Unicode $___content $___chars diff --git a/init/services/HestiaKERNEL/String/Trim_Suffix_String.sh b/init/services/HestiaKERNEL/String/Trim_Suffix_String.sh index 60d3d78..e6dbbac 100644 --- a/init/services/HestiaKERNEL/String/Trim_Suffix_String.sh +++ b/init/services/HestiaKERNEL/String/Trim_Suffix_String.sh @@ -9,7 +9,6 @@ # # You MUST ensure any interaction with the content STRICTLY COMPLIES with # the permissions and limitations set forth in the license. -. "${LIBS_HESTIA}/HestiaKERNEL/Errors/Error_Codes.sh" . "${LIBS_HESTIA}/HestiaKERNEL/String/To_String_From_Unicode.sh" . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Trim_Suffix_Unicode.sh" . "${LIBS_HESTIA}/HestiaKERNEL/Unicode/To_Unicode_From_String.sh" @@ -19,39 +18,16 @@ HestiaKERNEL_Trim_Suffix_String() { #___input="$1" - #___suffix="$2" - - - # validate input - if [ "$1" = "" ]; then - printf -- "%s" "$1" - return $HestiaKERNEL_ERROR_ENTITY_EMPTY - fi - - if [ "$2" = "" ]; then - printf -- "%s" "$1" - return $HestiaKERNEL_ERROR_DATA_EMPTY - fi + #___target="$2" # execute ___content="$(HestiaKERNEL_To_Unicode_From_String "$1")" - if [ "$___content" = "" ]; then - printf -- "%s" "$1" - return $HestiaKERNEL_ERROR_DATA_INVALID - fi - ___chars="$(HestiaKERNEL_To_Unicode_From_String "$2")" - if [ "$___chars" = "" ]; then - printf -- "%s" "$1" - return $HestiaKERNEL_ERROR_DATA_INVALID - fi - ___content="$(HestiaKERNEL_Trim_Suffix_Unicode "$___content" "$___chars")" - ___content="$(HestiaKERNEL_To_String_From_Unicode "$___content")" - printf -- "%s" "$___content" + printf -- "%s" "$(HestiaKERNEL_To_String_From_Unicode "$___content")" # report status - return $HestiaKERNEL_ERROR_OK + return $? } diff --git a/init/services/HestiaKERNEL/Unicode/Trim_Suffix_Unicode.ps1 b/init/services/HestiaKERNEL/Unicode/Trim_Suffix_Unicode.ps1 index 1740fcc..4d636ff 100644 --- a/init/services/HestiaKERNEL/Unicode/Trim_Suffix_Unicode.ps1 +++ b/init/services/HestiaKERNEL/Unicode/Trim_Suffix_Unicode.ps1 @@ -16,28 +16,28 @@ function HestiaKERNEL-Trim-Suffix-Unicode { param ( [uint32[]]$___content_unicode, - [uint32[]]$___suffix_unicode + [uint32[]]$___target_unicode ) # validate input if ( ($(HestiaKERNEL-Is-Unicode $___content_unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) -or - ($(HestiaKERNEL-Is-Unicode $___suffix_unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) + ($(HestiaKERNEL-Is-Unicode $___target_unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) ) { return $___content_unicode } - if ($___suffix_unicode.Length -gt $___content_unicode.Length) { + if ($___target_unicode.Length -gt $___content_unicode.Length) { return $___content_unicode } # execute $___index = $___content_unicode.Length - 1 - for ($i = $___suffix_unicode.Length - 1; $i -ge 0; $i--) { + for ($i = $___target_unicode.Length - 1; $i -ge 0; $i--) { # bail if mismatched - if ($___content_unicode[$___index] -ne $___suffix_unicode[$i]) { + if ($___content_unicode[$___index] -ne $___target_unicode[$i]) { return $___content_unicode } @@ -47,7 +47,6 @@ function HestiaKERNEL-Trim-Suffix-Unicode { if ($___index -le 0) { return [uint32[]]@() } - $___index += 1 # report status diff --git a/init/services/HestiaKERNEL/Unicode/Trim_Suffix_Unicode.sh b/init/services/HestiaKERNEL/Unicode/Trim_Suffix_Unicode.sh index 70af727..794293f 100644 --- a/init/services/HestiaKERNEL/Unicode/Trim_Suffix_Unicode.sh +++ b/init/services/HestiaKERNEL/Unicode/Trim_Suffix_Unicode.sh @@ -16,7 +16,7 @@ HestiaKERNEL_Trim_Suffix_Unicode() { #___content_unicode="$1" - #___charset_unicode="$2" + #___target_unicode="$2" # validate input @@ -33,8 +33,8 @@ HestiaKERNEL_Trim_Suffix_Unicode() { # execute ___content_unicode="$1" - ___suffix_unicode="$2" - while [ ! "$___suffix_unicode" = "" ]; do + ___target_unicode="$2" + while [ ! "$___target_unicode" = "" ]; do # get current character ___current="${___content_unicode##*, }" ___content_unicode="${___content_unicode%"$___current"}" @@ -44,16 +44,16 @@ HestiaKERNEL_Trim_Suffix_Unicode() { # get target character - ___target="${___suffix_unicode##*, }" - ___suffix_unicode="${___suffix_unicode%"$___target"}" - if [ "${___suffix_unicode#"${___suffix_unicode%?}"}" = " " ]; then - ___suffix_unicode="${___suffix_unicode%, }" + ___target="${___target_unicode##*, }" + ___target_unicode="${___target_unicode%"$___target"}" + if [ "${___target_unicode#"${___target_unicode%?}"}" = " " ]; then + ___target_unicode="${___target_unicode%, }" fi # bail if mismatched if [ "$___current" != "$___target" ] || - ([ "$___content_unicode" = "" ] && [ ! "$___suffix_unicode" = "" ]); then + ([ "$___content_unicode" = "" ] && [ ! "$___target_unicode" = "" ]); then printf -- "%s" "$1" return $HestiaKERNEL_ERROR_OK fi diff --git a/init/start.ps1 b/init/start.ps1 index 4b261e9..6a59266 100644 --- a/init/start.ps1 +++ b/init/start.ps1 @@ -227,12 +227,12 @@ Write-Host "----" Write-Host "---- Trim_Suffix_String ----" . "${env:LIBS_HESTIA}\HestiaKERNEL\String\Trim_Suffix_String.ps1" Write-Host "|$(HestiaKERNEL-Trim-Suffix-String "e你feeeff你你aerg aegE你F" '')|" -Write-Host "|$(HestiaKERNEL-Trim-Suffix-String '' "e你F")|" -Write-Host "|$(HestiaKERNEL-Trim-Suffix-String '' "e你a")|" +Write-Host "|$(HestiaKERNEL-Trim-Suffix-String '' "E你F")|" +Write-Host "|$(HestiaKERNEL-Trim-Suffix-String '' "E你A")|" Write-Host "|$(HestiaKERNEL-Trim-Suffix-String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你F")|" Write-Host "|$(HestiaKERNEL-Trim-Suffix-String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你FX")|" -Write-Host "|$(HestiaKERNEL-Trim-Suffix-String "e你feeeff你你aerg aegE你F" "e你a")|" -Write-Host "|$(HestiaKERNEL-Trim-Suffix-String "e你feeeff你你aerg aegE你F" "e你F")|" +Write-Host "|$(HestiaKERNEL-Trim-Suffix-String "e你feeeff你你aerg aegE你F" "E你A")|" +Write-Host "|$(HestiaKERNEL-Trim-Suffix-String "e你feeeff你你aerg aegE你F" "E你F")|" Write-Host "----" Write-Host "---- Get_Length_String ----"