Skip to content

Commit

Permalink
init: ported Index_Any_Right_{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_Right_{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 12, 2024
1 parent 434d5e4 commit c6b9abc
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 17 deletions.
31 changes: 31 additions & 0 deletions init/services/HestiaKERNEL/String/Index_Any_Right_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_Right_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\To_Unicode_From_String.ps1"




function HestiaKERNEL-Index-Any-Right-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-Right-Unicode $___content $___chars
}
31 changes: 31 additions & 0 deletions init/services/HestiaKERNEL/String/Index_Any_Right_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_Right_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/To_Unicode_From_String.sh"




HestiaKERNEL_Index_Any_Right_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_Right_Unicode "$___content" "$___chars")"


# report status
return $?
}
54 changes: 54 additions & 0 deletions init/services/HestiaKERNEL/Unicode/Index_Any_Right_Unicode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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-Right-Unicode {
param (
[uint32[]]$___content_unicode,
[uint32[]]$___target_unicode
)
$___scan_index = -1

# 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 $___scan_index
}

if ($___target_unicode.Length -gt $___content_unicode.Length) {
return $___scan_index
}


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


# scan character from given target
foreach ($___char in $___target_unicode) {
if ($___current -eq $___char) {
$___scan_index = $___index # exit early from O(m^2) timing ASAP
break scanner
}
}
}


# report status
return $___scan_index
}
109 changes: 109 additions & 0 deletions init/services/HestiaKERNEL/Unicode/Index_Any_Right_Unicode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# 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_Right_Unicode() {
#___content_unicode="$1"
#___target_unicode="$2"
___scan_index="-1"


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

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


# execute
___content_unicode="$1"
___target_unicode="$2"
___index=0
___is_scanning=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


# continue counting content length if scan is completed
if [ $___is_scanning -ne 0 ]; then
___index=$(($___index + 1))
continue
fi


# get char from target character
___target_unicode="$2"
___mismatched=0 ## assume mismatched by default
while [ ! "$___target_unicode" = "" ]; do
___target="${___target_unicode%%, *}"
___target_unicode="${___target_unicode#"$___target"}"
if [ "${___target_unicode%"${___target_unicode#?}"}" = "," ]; then
___target_unicode="${___target_unicode#, }"
fi

if [ "$___current" = "$___target" ]; then
___target_unicode=""
___mismatched=1
break # exit early from O(m^2) timing ASAP
fi
done


# bail if mismatched
if [ $___mismatched -eq 0 ]; then
___scan_index=-1
___index=$(($___index + 1))
continue
fi


# it's a match - set $___scan_index if available
if [ $___scan_index -lt 0 ]; then
___scan_index=$___index
___is_scanning=1
fi


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


# report early if the scan is negative
if [ $___scan_index -lt 0 ]; then
printf -- "%d" "-1"
return $HestiaKERNEL_ERROR_OK
fi


# convert right-to-left index back to left-to-right index for
# programming language's consistency
___scan_index="$(($___index - $___scan_index - 1))"


# report status
printf -- "%d" "$___scan_index"
return $HestiaKERNEL_ERROR_OK
}
5 changes: 0 additions & 5 deletions init/services/HestiaKERNEL/Unicode/Index_Right_Unicode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ function HestiaKERNEL-Index-Right-Unicode {
}


# convert right-to-left index back to left-to-right index for
# programming language's consistency
$___scan_index = $___scan_index - $___target_length


# report status
return $___scan_index
}
5 changes: 1 addition & 4 deletions init/services/HestiaKERNEL/Unicode/Index_Right_Unicode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ HestiaKERNEL_Index_Right_Unicode() {
___target_unicode="$2"
___index=0
___is_scanning=0
___target_length=0
while [ ! "$___content_unicode" = "" ]; do
# get current character
___current="${___content_unicode##*, }"
Expand Down Expand Up @@ -66,11 +65,9 @@ HestiaKERNEL_Index_Right_Unicode() {
if [ ! "$___current" = "$___target" ]; then
___scan_index=-1
___target_unicode="$2"
___target_length=0
___index=$(($___index + 1))
continue
fi
___target_length=$(($___target_length + 1))


# it's a match - set $___scan_index if available
Expand Down Expand Up @@ -99,7 +96,7 @@ HestiaKERNEL_Index_Right_Unicode() {

# convert right-to-left index back to left-to-right index for
# programming language's consistency
___scan_index="$(($___index - $___scan_index - $___target_length))"
___scan_index="$(($___index - $___scan_index - 1))"


# report status
Expand Down
35 changes: 30 additions & 5 deletions init/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,33 @@ Write-Host "----"
Write-Host "---- Index-Right-String ----"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Index_Right_String.ps1"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" '')|"
Write-Host "|$(HestiaKERNEL-Index-Right-String '' "e你f")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String '' "e你a")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String '' "E你F")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String '' "E你A")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你F")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你FX")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "e你a")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "e你f")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "a")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "E你A")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "E你F")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "F")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "z")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "")|"
Write-Host "|$(HestiaKERNEL-Index-Right-String "e你feeeff你你aerg aegE你F" "y我z")|"
Write-Host "----"

Write-Host "---- Index-Any-Right-String ----"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Index_Any_Right_String.ps1"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" '')|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String '' "E你F")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String '' "E你A")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你F")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你FX")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" "E你A")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" "E你F")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" "F")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" "")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" "z")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" "")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Right-String "e你feeeff你你aerg aegE你F" "y我z")|"
Write-Host "----"

Write-Host "---- Index-Left-String ----"
Expand All @@ -158,6 +177,9 @@ Write-Host "|$(HestiaKERNEL-Index-Left-String "e你feeeff你你aerg aegE你F" "e
Write-Host "|$(HestiaKERNEL-Index-Left-String "e你feeeff你你aerg aegE你F" "e你f")|"
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 "|$(HestiaKERNEL-Index-Left-String "e你feeeff你你aerg aegE你F" "z")|"
Write-Host "|$(HestiaKERNEL-Index-Left-String "e你feeeff你你aerg aegE你F" "")|"
Write-Host "|$(HestiaKERNEL-Index-Left-String "e你feeeff你你aerg aegE你F" "y我z")|"
Write-Host "----"

Write-Host "---- Index-Any-Left-String ----"
Expand All @@ -171,6 +193,9 @@ Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F
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 "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" "z")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" "")|"
Write-Host "|$(HestiaKERNEL-Index-Any-Left-String "e你feeeff你你aerg aegE你F" "y我z")|"
Write-Host "----"

Write-Host "---- Has_String ----"
Expand Down
31 changes: 28 additions & 3 deletions init/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,29 @@ LIBS_HESTIA="${LIBS_UPSCALER}/services"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "" "e你a")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你F")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你FX")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "e你a")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "e你f")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "a")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "E你A")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "E你F")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "F")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "z")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Right_String "e你feeeff你你aerg aegE你F" "y我z")"
1>&2 printf -- "----\n"

1>&2 printf -- "---- Index_Any_Right_String ----\n"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Index_Any_Right_String.sh"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "" "E你F")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "" "E你A")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你F")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "e你feeeff你你aerg aegE你FX")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "E你A")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "E你F")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "F")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "z")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Right_String "e你feeeff你你aerg aegE你F" "y我z")"
1>&2 printf -- "----\n"

1>&2 printf -- "---- Index_Left_String ----\n"
Expand All @@ -148,6 +167,9 @@ LIBS_HESTIA="${LIBS_UPSCALER}/services"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Left_String "e你feeeff你你aerg aegE你F" "e你f")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Left_String "e你feeeff你你aerg aegE你F" "a")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Left_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Left_String "e你feeeff你你aerg aegE你F" "z")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Left_String "e你feeeff你你aerg aegE你F" "")"
1>&2 printf -- "|%s|\n" "$(HestiaKERNEL_Index_Left_String "e你feeeff你你aerg aegE你F" "y我z")"
1>&2 printf -- "----\n"

1>&2 printf -- "---- Index_Any_Left_String ----\n"
Expand All @@ -161,6 +183,9 @@ LIBS_HESTIA="${LIBS_UPSCALER}/services"
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 -- "|%s|\n" "$(HestiaKERNEL_Index_Any_Left_String "e你feeeff你你aerg aegE你F" "z")"
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你feeeff你你aerg aegE你F" "y我z")"
1>&2 printf -- "----\n"

1>&2 printf -- "---- Has_String ----\n"
Expand Down

0 comments on commit c6b9abc

Please sign in to comment.