Skip to content

Commit

Permalink
init: ported Is_Empty_{String,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 Is_Empty_{String,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 5, 2024
1 parent 5fa1c33 commit abbb8c1
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 0 deletions.
37 changes: 37 additions & 0 deletions init/services/HestiaKERNEL/Is_Empty_String.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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\Error_Codes.ps1"




# IMPORTANT NOTICE
# This function is made available for backward compatibility and educational
# purposes (as a reminder on how to check without needing any other libraries)
# only. In practice, you should always use the "equal to empty string" tester
# directly such that:
# (1) POSIX Compliant Shell : if [ "$var" = "" ]; then
# (2) PowerShell : if ($var -eq "") {
function HestiaKERNEL-Is-Empty-String {
param (
[string]$___target
)


# execute
if ($___target -eq "") {
return ${env:HestiaKERNEL_ERROR_OK}
}


# report status
return ${env:HestiaKERNEL_ERROR_DATA_EMPTY}
}
38 changes: 38 additions & 0 deletions init/services/HestiaKERNEL/Is_Empty_String.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/Error_Codes.sh"




# IMPORTANT NOTICE
# This function is made available for backward compatibility and educational
# purposes (as a reminder on how to check without needing any other libraries)
# only. In practice, you should always use the "equal to empty string" tester
# directly such that:
# (1) POSIX Compliant Shell : if [ "$var" = "" ]; then
# (2) PowerShell : if ($var -eq "") {
HestiaKERNEL_Is_Empty_String() {
#___target="$1"


# execute
if [ "$1" = "" ]; then
printf -- "%d" $HestiaKERNEL_ERROR_OK
return $HestiaKERNEL_ERROR_OK
fi


# report status
printf -- "%d" $HestiaKERNEL_ERROR_DATA_EMPTY
return $HestiaKERNEL_ERROR_DATA_EMPTY
}
37 changes: 37 additions & 0 deletions init/services/HestiaKERNEL/Is_Empty_Unicode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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\Error_Codes.ps1"




# IMPORTANT NOTICE
# This function is made available for backward compatibility and educational
# purposes (as a reminder on how to check without needing any other libraries)
# only. In practice, you should always use the "equal to empty array" tester
# directly such that:
# (1) POSIX Compliant Shell : if [ "$var" = "" ]; then
# (2) PowerShell : if ($var.Length -le 0) {
function HestiaKERNEL-Is-Empty-Unicode {
param (
[uint32[]]$___target
)


# execute
if ($___target.Length -le 0) {
return ${env:HestiaKERNEL_ERROR_OK}
}


# report status
return ${env:HestiaKERNEL_ERROR_DATA_EMPTY}
}
38 changes: 38 additions & 0 deletions init/services/HestiaKERNEL/Is_Empty_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/Error_Codes.sh"




# IMPORTANT NOTICE
# This function is made available for backward compatibility and educational
# purposes (as a reminder on how to check without needing any other libraries)
# only. In practice, you should always use the "equal to empty string" tester
# directly such that:
# (1) POSIX Compliant Shell : if [ "$var" = "" ]; then
# (2) PowerShell : if ($var -eq "") {
HestiaKERNEL_Is_Empty_Unicode() {
#___target="$1"


# execute
if [ "$1" = "" ]; then
printf -- "%d" $HestiaKERNEL_ERROR_OK
return $HestiaKERNEL_ERROR_OK
fi


# report status
printf -- "%d" $HestiaKERNEL_ERROR_DATA_EMPTY
return $HestiaKERNEL_ERROR_DATA_EMPTY
}
4 changes: 4 additions & 0 deletions init/services/HestiaKERNEL/Vanilla.sh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null
. "${env:LIBS_HESTIA}\HestiaKERNEL\Error_Codes.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Get_String_Encoder.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Array_Number.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Empty_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Empty_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Punctuation_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Punctuation_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Unicode.ps1"
Expand Down Expand Up @@ -77,6 +79,8 @@ RUN_AS_POWERSHELL
. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Get_String_Encoder.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Array_Number.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Empty_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Empty_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Punctuation_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Punctuation_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Unicode.sh"
Expand Down
8 changes: 8 additions & 0 deletions init/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ ${env:LIBS_HESTIA} = "${env:LIBS_UPSCALER}\services"
. "${env:LIBS_UPSCALER}\services\i18n\report-success.ps1"

### TEST ZONE
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Empty_String.ps1"
Write-Host "$(HestiaKERNEL-Is-Empty-String '')"
Write-Host "$(HestiaKERNEL-Is-Empty-String "a")"

. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Empty_Unicode.ps1"
Write-Host "$(HestiaKERNEL-Is-Empty-Unicode @())"
Write-Host "$(HestiaKERNEL-Is-Empty-Unicode @(45, 54))"

. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Whitespace_String.ps1"
Write-Host "$(HestiaKERNEL-Is-Whitespace-String " ")"
Write-Host "$(HestiaKERNEL-Is-Whitespace-String "m")"
Expand Down
8 changes: 8 additions & 0 deletions init/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ LIBS_HESTIA="${LIBS_UPSCALER}/services"
. "${LIBS_UPSCALER}/services/i18n/report-success.sh"

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

. "${LIBS_HESTIA}/HestiaKERNEL/Is_Empty_Unicode.sh"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Empty_Unicode "")"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Empty_Unicode "45, 54")"

. "${LIBS_HESTIA}/HestiaKERNEL/Is_Whitespace_String.sh"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Whitespace_String " ")"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Whitespace_String "m")"
Expand Down

0 comments on commit abbb8c1

Please sign in to comment.