Skip to content

Commit

Permalink
init: ported Get_First_{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 Get_First_{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 5, 2024
1 parent abbb8c1 commit df84c2b
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 0 deletions.
45 changes: 45 additions & 0 deletions init/services/HestiaKERNEL/Get_First_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\Get_First_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_String_From_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_Unicode_From_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode.ps1"




function HestiaKERNEL-Get-First-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-First-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/Get_First_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/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Get_First_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_String_From_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_Unicode_From_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode.sh"




HestiaKERNEL_Get_First_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_First_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/Get_First_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.ps1"




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


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


# execute
return $___content_unicode[0]
}
38 changes: 38 additions & 0 deletions init/services/HestiaKERNEL/Get_First_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"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode.sh"




HestiaKERNEL_Get_First_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
}
6 changes: 6 additions & 0 deletions init/services/HestiaKERNEL/Unicode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@



# Error type
${env:HestiaKERNEL_UNICODE_ERROR} = [uint32]4294967295 # 0xFFFFFFFF




# BOM type
${env:HestiaKERNEL_UTF_NO_BOM} = 0 # default
${env:HestiaKERNEL_UTF_BOM} = 1
Expand Down
6 changes: 6 additions & 0 deletions init/services/HestiaKERNEL/Unicode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@



# Error type
HestiaKERNEL_UNICODE_ERROR=4294967295 # 0xFFFFFFFF




# BOM type
HestiaKERNEL_UTF_NO_BOM=0 # default
HestiaKERNEL_UTF_BOM=1
Expand Down
5 changes: 5 additions & 0 deletions init/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ ${env:LIBS_HESTIA} = "${env:LIBS_UPSCALER}\services"
. "${env:LIBS_UPSCALER}\services\i18n\report-success.ps1"

### TEST ZONE
. "${env:LIBS_HESTIA}\HestiaKERNEL\Get_First_Character.ps1"
Write-Host "$(HestiaKERNEL-Get-First-Character '')"
Write-Host "$(HestiaKERNEL-Get-First-Character "s")"
Write-Host "$(HestiaKERNEL-Get-First-Character "sta")"

. "${env:LIBS_HESTIA}\HestiaKERNEL\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 @@ -102,6 +102,11 @@ LIBS_HESTIA="${LIBS_UPSCALER}/services"
. "${LIBS_UPSCALER}/services/i18n/report-success.sh"

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

. "${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")"
Expand Down

0 comments on commit df84c2b

Please sign in to comment.