Skip to content

Commit

Permalink
init: ported Get_Last_{Character,Unicode} primitive function
Browse files Browse the repository at this point in the history
Since a number of level 1 Hestia libraries use string functions,
we have to port its primitive ones into HestiaKERNEL library package.
Hence, let's do this.

This patch ports Get_Last_{Char,Unicode} primitive function
into HestiaKERNEL library in 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 6, 2024
1 parent 97f6cc7 commit 67d153d
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 0 deletions.
45 changes: 45 additions & 0 deletions init/services/HestiaKERNEL/String/Get_Last_Character.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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\Get_Last_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\To_Unicode_From_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Unicode.ps1"




function HestiaKERNEL-Get-Last-Character {
param (
[string]$___input_string
)


# validate input
if ($___input_string -eq "") {
return ""
}


# execute
$___unicodes = HestiaKERNEL-To-Unicode-From-String $___input_string
if ($___unicodes.Length -le 0) {
return ""
}

$___unicode = HestiaKERNEL-Get-Last-Unicode $___unicodes
if ($___unicode -eq ${env:HestiaKERNEL_UNICODE_ERROR}) {
return ""
}


# execute
return HestiaKERNEL-To-String-From-Unicode $___unicode
}
53 changes: 53 additions & 0 deletions init/services/HestiaKERNEL/String/Get_Last_Character.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/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/String/To_String_From_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Get_Last_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/To_Unicode_From_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Unicode.sh"




HestiaKERNEL_Get_Last_Character() {
#___input_string="$1"


# validate input
if [ "$1" = "" ]; then
printf -- ""
return $HestiaKERNEL_ERROR_DATA_EMPTY
fi


# execute
___unicodes="$(HestiaKERNEL_To_Unicode_From_String "$1")"
if [ "$___unicodes" = "" ]; then
printf -- ""
return $HestiaKERNEL_ERROR_DATA_INVALID
fi

___unicode="$(HestiaKERNEL_Get_Last_Unicode "$___unicodes")"
if [ "$___unicode" = "${HestiaKERNEL_UNICODE_ERROR}" ]; then
printf -- ""
return $HestiaKERNEL_ERROR_DATA_INVALID
fi

printf -- "%s" "$(HestiaKERNEL_To_String_From_Unicode "$___unicode")"
if [ $? -ne $HestiaKERNEL_ERROR_OK ]; then
return $HestiaKERNEL_ERROR_BAD_EXEC
fi


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




function HestiaKERNEL-Get-Last-Unicode {
param (
[uint32[]]$___content_unicode
)


# validate input
if ($___content_unicode.Length -le 0) {
return ${env:HestiaKERNEL_UNICODE_ERROR}
}


# execute
return $___content_unicode[-1]
}
38 changes: 38 additions & 0 deletions init/services/HestiaKERNEL/Unicode/Get_Last_Unicode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Unicode.sh"




HestiaKERNEL_Get_Last_Unicode() {
#___content_unicode="$1"


# validate input
if [ "$1" = "" ]; then
printf -- "%s" "$HestiaKERNEL_UNICODE_ERROR"
return $HestiaKERNEL_ERROR_ENTITY_EMPTY
fi

if [ "$(HestiaKERNEL_Is_Unicode "$1")" -ne $HestiaKERNEL_ERROR_OK ]; then
printf -- "%s" "$HestiaKERNEL_UNICODE_ERROR"
return $HestiaKERNEL_ERROR_ENTITY_INVALID
fi


# execute
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 @@ -40,6 +40,7 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null
. "${env:LIBS_HESTIA}\HestiaKERNEL\OS\Get_String_Encoder.ps1"
. "${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\Is_Empty_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Is_Punctuation_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Is_Whitespace_String.ps1"
Expand All @@ -50,6 +51,7 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Trim_Left_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Trim_Right_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\Is_Empty_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Is_Punctuation_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Is_Unicode.ps1"
Expand Down Expand Up @@ -89,6 +91,7 @@ RUN_AS_POWERSHELL
. "${LIBS_HESTIA}/HestiaKERNEL/OS/Get_String_Encoder.sh"
. "${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/Is_Empty_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Is_Punctuation_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Is_Whitespace_String.sh"
Expand All @@ -99,6 +102,7 @@ RUN_AS_POWERSHELL
. "${LIBS_HESTIA}/HestiaKERNEL/String/Trim_Left_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/String/Trim_Right_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Get_First_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Get_Last_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Is_Empty_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Is_Punctuation_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Is_Unicode.sh"
Expand Down
5 changes: 5 additions & 0 deletions init/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ Write-Host "$(HestiaKERNEL-Get-First-Character '')"
Write-Host "$(HestiaKERNEL-Get-First-Character "s")"
Write-Host "$(HestiaKERNEL-Get-First-Character "sta")"

. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Get_Last_Character.ps1"
Write-Host "$(HestiaKERNEL-Get-Last-Character '')"
Write-Host "$(HestiaKERNEL-Get-Last-Character "s")"
Write-Host "$(HestiaKERNEL-Get-Last-Character "sta")"

. "${env:LIBS_HESTIA}\HestiaKERNEL\String\Is_Empty_String.ps1"
Write-Host "$(HestiaKERNEL-Is-Empty-String '')"
Write-Host "$(HestiaKERNEL-Is-Empty-String "a")"
Expand Down
5 changes: 5 additions & 0 deletions init/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ LIBS_HESTIA="${LIBS_UPSCALER}/services"
1>&2 printf -- "%s\n" "$(HestiaKERNEL_Get_First_Character "s")"
1>&2 printf -- "%s\n" "$(HestiaKERNEL_Get_First_Character "sta")"

. "${LIBS_HESTIA}/HestiaKERNEL/String/Get_Last_Character.sh"
1>&2 printf -- "%s\n" "$(HestiaKERNEL_Get_Last_Character "")"
1>&2 printf -- "%s\n" "$(HestiaKERNEL_Get_Last_Character "s")"
1>&2 printf -- "%s\n" "$(HestiaKERNEL_Get_Last_Character "sta")"

. "${LIBS_HESTIA}/HestiaKERNEL/String/Is_Empty_String.sh"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Empty_String "")"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Empty_String "s")"
Expand Down

0 comments on commit 67d153d

Please sign in to comment.