Skip to content

Commit

Permalink
root: cleaned up HestiaKERNEL porting
Browse files Browse the repository at this point in the history
It appears there were some modifications here and here during the
HestiaKERNEL porting. Hence, let's clean them up for now.

This patch cleans up the HestiaKERNEL porting in root repository.

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 Oct 9, 2024
1 parent f4af2a0 commit 50936d6
Show file tree
Hide file tree
Showing 34 changed files with 193 additions and 220 deletions.
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Endian.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Endian.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Error_Codes.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Error_Codes.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Get_String_Encoder.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Get_String_Encoder.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down
8 changes: 4 additions & 4 deletions init/services/HestiaKERNEL/Is_UTF.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

function HestiaKERNEL-Is-UTF {
param (
[uint8[]]$___byte_array
[byte[]]$___byte_array
)


Expand Down Expand Up @@ -64,7 +64,7 @@ function HestiaKERNEL-Is-UTF {
# get current byte ($___content[0])
$___byte = $___byte_array[0]
$___content = $___byte_array.Substring(1)
$___byte = [uint8]$___byte[0]
$___byte = [byte]$___byte[0]


# save to sample positions for BOM analysis
Expand All @@ -79,7 +79,7 @@ function HestiaKERNEL-Is-UTF {
$___byte_3 = $___byte
} default {
# do nothing
}
}}


# scan UTF-8 header for its validity
Expand Down Expand Up @@ -150,7 +150,7 @@ function HestiaKERNEL-Is-UTF {
($___byte_0 -eq 0) -and
($___byte_1 -eq 0) -and
($___byte_2 -eq 254) -and
($___byte_3 -eq 255) -and
($___byte_3 -eq 255)
) {
# it's UTF32BE_BOM
return ${env:HestiaKERNEL_UTF32BE_BOM}
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Is_Unicode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

function HestiaKERNEL-Is-Unicode {
param (
[uint32]$___content
[uint32[]]$___content
)


Expand Down
4 changes: 2 additions & 2 deletions init/services/HestiaKERNEL/Is_Unicode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ HestiaKERNEL_Is_Unicode() {

# execute
case "$1" in
*[!0123456789]*)
printf -- ""
*[!0123456789,\ ]*)
printf -- "%d" $HestiaKERNEL_ERROR_DATA_INVALID
return $HestiaKERNEL_ERROR_DATA_INVALID
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Is_Whitespace_Unicode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function HestiaKERNEL-Is-Whitespace-Unicode {


# execute
switch ($___unicode) in {
switch ($___unicode) {
{ $_ -in 9, 10, 11, 12, 13, 32, 133, 160 } {
# 9 | 10 | 11 | 12 | 13 | 32 | 133 | 160
# 0x0009|0x000A|0x000B|0x000C|0x000D|0x0020|0x0085|0x00A0
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Run_Parallel_Sentinel.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Run_Parallel_Sentinel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/To_Lowercase_Unicode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function HestiaKERNEL-To-Lowercase-Unicode {
$___ret = $___ret -replace "^\[\d*\]", ''
while ($___ret -ne "") {
$___byte = $___ret -replace ",\s.*$", ''
$___ret = $___ret -replace "^\d*,\s", ''
$___ret = $___ret -replace "^\d*\,?\s?", ''
$null = $___converted.Add([uint32]$___byte)
}

Expand Down
23 changes: 5 additions & 18 deletions init/services/HestiaKERNEL/To_String_From_Unicode.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down Expand Up @@ -27,10 +27,9 @@
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Error_Codes.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Get_String_Encoder.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_UTF8_From_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_UTF16_From_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_UTF32_From_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode.ps1"


Expand All @@ -43,26 +42,14 @@ function HestiaKERNEL-To-String-From-Unicode {


# validate input
if ($___unicode.Length -eq 0) {
if ($(HestiaKERNEL-Is-Unicode $___unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) {
return ""
}


# execute
# process HestiaKERNEL.Unicode data type as the last resort
switch (HestiaKERNEL-Get-String-Encoder) {
${env:HestiaKERNEL_UTF8} {
$___utf = HestiaKERNEL-To-UTF8-From-Unicode $___unicode
} ${env:HestiaKERNEL_UTF16BE} {
$___utf = HestiaKERNEL-To-UTF16-From-Unicode $___unicode
} ${env:HestiaKERNEL_UTF32BE} {
$___utf = HestiaKERNEL-To-UTF32-From-Unicode $___unicode
} default {
return ""
}

$___converted = ""
foreach ($___byte in $___utf) {
foreach ($___byte in $___unicode) {
$___converted = "${___converted}$([string][char]$___byte)"
}

Expand Down
15 changes: 4 additions & 11 deletions init/services/HestiaKERNEL/To_String_From_Unicode.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down Expand Up @@ -30,6 +30,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Get_String_Encoder.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_UTF8_From_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_UTF16_From_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_UTF32_From_Unicode.sh"
Expand All @@ -43,17 +44,10 @@ HestiaKERNEL_To_String_From_Unicode() {


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

case "$1" in
*[!0123456789\ \,]*)
if [ $(HestiaKERNEL_Is_Unicode "$1") -ne "$HestiaKERNEL_ERROR_OK" ]; then
printf -- ""
return $HestiaKERNEL_ERROR_DATA_INVALID
;;
esac
fi


# execute
Expand All @@ -80,7 +74,6 @@ HestiaKERNEL_To_String_From_Unicode() {
return $HestiaKERNEL_ERROR_DATA_INVALID
fi


___converted=""
while [ ! "$___utf" = "" ]; do
___byte="${___utf%%, *}"
Expand Down
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/To_Titlecase_String.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function HestiaKERNEL-To-Titlecase-String {
return $___input
}

$___content = HestiaKERNEL-To-Titlecase-Unicode $___input
$___content = HestiaKERNEL-To-Titlecase-Unicode $___content
if ($___content.Length -eq 0) {
return $___input
}
Expand Down
6 changes: 3 additions & 3 deletions init/services/HestiaKERNEL/To_Titlecase_Unicode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function HestiaKERNEL-To-Titlecase-Unicode {
# contents at the end of an iteration.
[System.Collections.Generic.List[uint32]]$___converted = @()
$___index = 0
$___to_title = ""
$___to_title = "true"
$___length = $___unicode.Length - 1
while ($___index -le $___length) {
# get current character
Expand Down Expand Up @@ -88,7 +88,7 @@ function HestiaKERNEL-To-Titlecase-Unicode {


# process conversion
$___ret = hestiakernel-rune-to-upper `
$___ret = hestiakernel-rune-to-title `
$___current `
$___next `
$___third `
Expand All @@ -98,7 +98,7 @@ function HestiaKERNEL-To-Titlecase-Unicode {
$___ret = $___ret -replace "^\[\d*\]", ''
while ($___ret -ne "") {
$___byte = $___ret -replace ",\s.*$", ''
$___ret = $___ret -replace "^\d*,\s", ''
$___ret = $___ret -replace "^\d*\,?\s?", ''
$null = $___converted.Add([uint32]$___byte)
}

Expand Down
16 changes: 9 additions & 7 deletions init/services/HestiaKERNEL/To_UTF16_From_Unicode.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down Expand Up @@ -27,28 +27,30 @@
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Error_Codes.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Endian.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode.ps1"




function HestiaKERNEL-To-UTF16-From-Unicode {
param (
[uint32[]]$___content,
[uint32[]]$___unicode,
[string]$___bom,
[string]$___endian
)


# validate input
if ($___content.Length -eq 0) {
return [uint8[]]@()
if ($(HestiaKERNEL-Is-Unicode $___unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) {
return [byte[]]@()
}


# execute
[System.Collections.Generic.List[uint8]]$___converted = @()
[System.Collections.Generic.List[byte]]$___converted = @()
if ($___bom -eq ${env:HestiaKERNEL_UTF_BOM}) {
switch ($___endian) {
${env:HestiaKERNEL_ENDIAN_LITTLE} {
Expand All @@ -62,7 +64,7 @@ function HestiaKERNEL-To-UTF16-From-Unicode {
}}
}

foreach ($___char in $___content) {
foreach ($___char in $___unicode) {
# convert to UTF-16 bytes list
# IMPORTANT NOTICE
# (1) using single code-point algorithm (not the 2 16-bits).
Expand Down Expand Up @@ -125,5 +127,5 @@ function HestiaKERNEL-To-UTF16-From-Unicode {


# report status
return [uint8[]]$___converted
return [byte[]]$___converted
}
16 changes: 5 additions & 11 deletions init/services/HestiaKERNEL/To_UTF16_From_Unicode.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2024 (Holloway) Chew, Kean Ho <[email protected]>
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
Expand Down Expand Up @@ -30,29 +30,23 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. "${LIBS_HESTIA}/HestiaKERNEL/Endian.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode.sh"




HestiaKERNEL_To_UTF16_From_Unicode() {
#___content="$1"
#___unicode="$1"
#___bom="$2"
#___endian="$3"


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

case "$1" in
*[!0123456789\ \,]*)
if [ "$(HestiaKERNEL_Is_Unicode "$1")" -ne $HestiaKERNEL_ERROR_OK ]; then
printf -- ""
return $HestiaKERNEL_ERROR_DATA_INVALID
;;
esac
fi


# execute
Expand Down
Loading

0 comments on commit 50936d6

Please sign in to comment.