Skip to content

Commit

Permalink
init: ported Index_Any_{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 Index_Any_{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 11, 2024
1 parent e9acbed commit 434d5e4
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 0 deletions.
31 changes: 31 additions & 0 deletions init/services/HestiaKERNEL/String/Index_Any_Left_String.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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\Index_Any_Left_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\To_Unicode_From_String.ps1"




function HestiaKERNEL-Index-Any-Left-String {
param (
[string]$___input,
[string]$___target
)


# execute
$___content = HestiaKERNEL-To-Unicode-From-String $___input
$___chars = HestiaKERNEL-To-Unicode-From-String $___target


# report status
return HestiaKERNEL-Index-Any-Left-Unicode $___content $___chars
}
31 changes: 31 additions & 0 deletions init/services/HestiaKERNEL/String/Index_Any_Left_String.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/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/Unicode/Index_Any_Left_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/To_Unicode_From_String.sh"




HestiaKERNEL_Index_Any_Left_String() {
#___input="$1"
#___target="$2"


# execute
___content="$(HestiaKERNEL_To_Unicode_From_String "$1")"
___chars="$(HestiaKERNEL_To_Unicode_From_String "$2")"
printf -- "%d" "$(HestiaKERNEL_Index_Any_Left_Unicode "$___content" "$___chars")"


# report status
return $?
}
49 changes: 49 additions & 0 deletions init/services/HestiaKERNEL/Unicode/Index_Any_Left_Unicode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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\Is_Unicode.ps1"




function HestiaKERNEL-Index-Any-Left-Unicode {
param (
[uint32[]]$___content_unicode,
[uint32[]]$___target_unicode
)


# validate input
if (
($(HestiaKERNEL-Is-Unicode $___content_unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) -or
($(HestiaKERNEL-Is-Unicode $___target_unicode) -ne ${env:HestiaKERNEL_ERROR_OK})
) {
return -1
}


# execute
for ($___index = 0; $___index -le $___content_unicode.Length - 1; $___index++) {
# get current character
$___current = $___content_unicode[$___index]


# scan character from given charset
foreach ($___char in $___target_unicode) {
if ($___current -eq $___char) {
return $___index # exit early from O(m^2) timing ASAP
}
}
}


# report status
return -1
}
71 changes: 71 additions & 0 deletions init/services/HestiaKERNEL/Unicode/Index_Any_Left_Unicode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/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/Errors/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Is_Unicode.sh"




HestiaKERNEL_Index_Any_Left_Unicode() {
#___content_unicode="$1"
#___target_unicode="$2"


# validate input
if [ $(HestiaKERNEL_Is_Unicode "$1") -ne $HestiaKERNEL_ERROR_OK ]; then
printf -- "%d" "-1"
return $HestiaKERNEL_ERROR_ENTITY_EMPTY
fi

if [ $(HestiaKERNEL_Is_Unicode "$2") -ne $HestiaKERNEL_ERROR_OK ]; then
printf -- "%d" "-1"
return $HestiaKERNEL_ERROR_DATA_EMPTY
fi


# execute
___content_unicode="$1"
___index=0
while [ ! "$___content_unicode" = "" ]; do
# get current character
___current="${___content_unicode%%, *}"
___content_unicode="${___content_unicode#"$___current"}"
if [ "${___content_unicode%"${___content_unicode#?}"}" = "," ]; then
___content_unicode="${___content_unicode#, }"
fi


# get char from target character
___target_unicode="$2"
while [ ! "$___target_unicode" = "" ]; do
___char="${___target_unicode%%, *}"
___target_unicode="${___target_unicode#"$___char"}"
if [ "${___target_unicode%"${___target_unicode#?}"}" = "," ]; then
___target_unicode="${___target_unicode#, }"
fi

if [ "$___current" = "$___char" ]; then
printf -- "%d" "$___index"
return $HestiaKERNEL_ERROR_OK # exit early from O(m^2) timing ASAP
fi
done


# more characters - increase index and continue
___index=$(($___index + 1))
done


# report status
printf -- "%d" "-1"
return $HestiaKERNEL_ERROR_OK
}
4 changes: 4 additions & 0 deletions init/services/HestiaKERNEL/Vanilla.sh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null
. "${env:LIBS_HESTIA}\HestiaKERNEL\Parallelism\Run_Parallel_Sentinel.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Get_First_Character.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Get_Last_Character.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Index_Any_Left_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Index_Left_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Index_Right_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Index_String.ps1"
Expand All @@ -60,6 +61,7 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Trim_Whitespace_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Get_First_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Get_Last_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Index_Any_Left_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Index_Left_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Index_Right_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Index_Unicode.ps1"
Expand Down Expand Up @@ -108,6 +110,7 @@ RUN_AS_POWERSHELL
. "${LIBS_HESTIA}/HestiaKERNEL/Parallelism/Run_Parallel_Sentinel.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Get_First_Character.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Get_Last_Character.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Index_Any_Left_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Index_Left_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Index_Right_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Index_String.sh"
Expand All @@ -127,6 +130,7 @@ RUN_AS_POWERSHELL
. "${LIBS_HESTIA}/HestiaKERNEL/String/Trim_Whitespace_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Get_First_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Get_Last_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Index_Any_Left_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Index_Left_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Index_Right_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Index_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 @@ -160,6 +160,19 @@ Write-Host "|$(HestiaKERNEL-Index-Left-String "e你feeeff你你aerg aegE你F" "a
Write-Host "|$(HestiaKERNEL-Index-Left-String "e你feeeff你你aerg aegE你F" "")|"
Write-Host "----"

Write-Host "---- Index-Any-Left-String ----"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Index_Any_Left_String.ps1"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" '')|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String '' "e你f")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String '' "e你a")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你F")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你FX")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" "e你a")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" "e你f")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" "a")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" "")|"
Write-Host "----"

Write-Host "---- Has_String ----"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Has_String.ps1"
Write-Host "|$(HestiaKERNEL-Has-String "e你feeeff你你aerg aegE你F" '')|"
Expand Down
13 changes: 13 additions & 0 deletions init/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ LIBS_HESTIA="${LIBS_UPSCALER}/services"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Left_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "----\n"

1>&2 printf -- "---- Index_Any_Left_String ----\n"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Index_Any_Left_String.sh"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "" "e你f")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "" "e你a")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你F")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你FX")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "e你feeeff你你aerg aegE你F" "e你a")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "e你feeeff你你aerg aegE你F" "e你f")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "e你feeeff你你aerg aegE你F" "a")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "----\n"

1>&2 printf -- "---- Has_String ----\n"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Has_String.sh"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Has_String "e你feeeff你你aerg aegE你F" "")"
Expand Down

0 comments on commit 434d5e4

Please sign in to comment.