Skip to content

Commit

Permalink
init: ported To_Uppercase_{String,Unicode} primitive function
Browse files Browse the repository at this point in the history
Since the level 2 Hestia libraries require some string function,
we have to port those primitive functions into HestiaKERNEL. Hence,
let's do this.

This patch ports To_Uppercase_{String,Unicde} primitive function
into HestiaKERNEL 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 Oct 4, 2024
1 parent c0d6fa6 commit 8595e38
Show file tree
Hide file tree
Showing 10 changed files with 5,262 additions and 4 deletions.
7 changes: 7 additions & 0 deletions init/services/HestiaKERNEL/To_String_From_Unicode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ HestiaKERNEL_To_String_From_Unicode() {
return $HestiaKERNEL_ERROR_DATA_EMPTY
fi

case "$1" in
*[!0123456789\ \,]*)
printf -- ""
return $HestiaKERNEL_ERROR_DATA_INVALID
;;
esac


# execute
# process HestiaKERNEL.Unicode data type
Expand Down
6 changes: 3 additions & 3 deletions init/services/HestiaKERNEL/To_Unicode_From_String.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function HestiaKERNEL-To-Unicode-From-String {

# validate input
if ($___content -eq "") {
return @()
return [uint32[]]@()
}


Expand All @@ -63,7 +63,7 @@ function HestiaKERNEL-To-Unicode-From-String {
# UTF8, UTF16, and UTF32 are the candidates - try to parse
} else {
# unsupported decoders
return @()
return [uint32[]]@()
}


Expand All @@ -85,5 +85,5 @@ function HestiaKERNEL-To-Unicode-From-String {


# report status
return [array]$___converted
return [uint32[]]$___converted
}
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/To_Unicode_From_String.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ HestiaKERNEL_To_Unicode_From_String() {


# check for data encoder
___output="$(HestiaSTRING_Is_Unicode "$1")"
___output="$(HestiaKERNEL_Is_Unicode "$1")"
if [ ! "${___output#*"$HestiaKERNEL_UTF8"}" = "$___output" ] ||
[ ! "${___output#*"$HestiaKERNEL_UTF8_BOM"}" = "$___output" ] ||
[ ! "${___output#*"$HestiaKERNEL_UTF16BE"}" = "$___output" ] ||
Expand Down
64 changes: 64 additions & 0 deletions init/services/HestiaKERNEL/To_Uppercase_String.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# 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}\HestiaSTRING\To_Uppercase_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaSTRING\To_Unicode_From_String.ps1"
. "${env:LIBS_HESTIA}\HestiaSTRING\To_String_From_Unicode.ps1"




function HestiaKERNEL-To-Uppercase-String {
param (
[string]$___input,
[string]$___locale
)


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


# execute
$___content = HestiaKERNEL-To-Unicode-From-String $___input
if ($___content.Length -eq 0) {
return ""
}

$___content = HestiaKERNEL-To-Uppercase-Unicode $___content
if ($___content.Length -eq 0) {
return ""
}


# report status
return HestiaKERNEL-To-String-From-Unicode $___content
}
68 changes: 68 additions & 0 deletions init/services/HestiaKERNEL/To_Uppercase_String.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# 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.
. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_Upppercase_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_Unicode_From_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_String_From_Unicode.sh"




HestiaKERNEL_To_Uppercase_String() {
#___input="$1"
#___locale="$2"


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


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

___content="$(HestiaKERNEL_To_Uppercase_Unicode "$___content")"
if [ "$___content" = "" ]; then
printf -- "%s" "$1"
return $HestiaKERNEL_ERROR_BAD_EXEC
fi


# report status
printf -- "%s" "$(HestiaKERNEL_To_String_From_Unicode "$___content")"
return $HestiaKERNEL_ERROR_OK
}
92 changes: 92 additions & 0 deletions init/services/HestiaKERNEL/To_Uppercase_Unicode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# 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\rune_to_upper.ps1"




function HestiaKERNEL-To-Uppercase-Unicode {
param (
[uint32[]]$___unicode,
[string]$___locale
)


# execute
if ($___unicode.Length -eq 0) {
return $___unicode
}


# IMPORTANT NOTICE
# It's tempting to use the for(...arithmetic...) loop -> DON'T. The
# scanner do perform multiple index increment depending on the scanned
# contents at the end of an iteration.
[System.Collections.Generic.List[uint32]]$___converted = @()
$___index = 0
$___length = $___content.Length - 1
while ($___index -le $___length) {
# get current character
$___current = $___content[$___index]


# get next character (look forward by 1)
$___next = 0
if (($___length - $___index) -ge 1) {
$___next = $___content[$___index + 1]
}


# get third character (look forward by 2)
$___third = 0
if (($___length - $___index) -ge 2) {
$___third = $___content[$___index + 2]
}


# process conversion
$___ret = hestiakernel-rune-to-upper $___current $___next $___third "" $___locale
$___scanned = $___ret -replace "].*$", ''
$___ret = $___ret -replace "^\[\d*\]", ''
while ($___ret -ne "") {
$___byte = $___ret -replace ",\s.*$", ''
$___ret = $___ret -replace "^\d*,\s", ''
$null = $___converted.Add([uint32]$___byte)
}


# prepare for next scan
$___index += [uint32]$___scanned.Substring(1)
}


# report status
return [uint32[]]$___converted
}
119 changes: 119 additions & 0 deletions init/services/HestiaKERNEL/To_Uppercase_Unicode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# BSD 3-Clause License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# 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.
. "${LIBS_HESTIA}/HestiaKERNEL/rune_to_upper.sh"

. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"




HestiaKERNEL_To_Uppercase_Unicode() {
#___unicode="$1"
#___locale="$2"


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

case "$1" in
*[!0123456789\ \,]*)
printf -- ""
return $HestiaKERNEL_ERROR_DATA_INVALID
;;
esac


# execute
___content="$1"
___converted=""
while [ ! "$___content" = "" ]; do
# get current character
___current="${___content%%, *}"
___content="${___content#"$___current"}"
if [ "${___content%"${___content#?}"}" = "," ]; then
___content="${___content#, }"
fi


# get next character (look forward by 1)
___next=0
if [ ! "$___content" = "" ]; then
___next="${___content%%, *}"
fi


# get third character (look forward by 2)
___third="${___content#${___next}}"
if [ ! "$___third" = "" ]; then
if [ "${___third%"${___third#?}"}" = "," ]; then
___third="${___third#, }"
fi

___third="${___third%%, *}"
if [ "$___third" = "" ]; then
___third=0
fi
else
___third=0
fi


# proceed to default conversion
___ret="$(hestiakernel_rune_to_upper "$___current" "$___next" "$___third" "" "$2")"
___scanned="${___ret%%]*}"
___converted="${___converted}${___ret#*]}, "


# prepare for next scan
___scanned="${___scanned#[}"
while [ $___scanned -gt 1 ]; do
if [ "$___content" = "" ]; then
break
fi

___current="${___content%%, *}"
___content="${___content#"$___char"}"
if [ "${___content%"${___content#?}"}" = "," ]; then
___content="${___content#, }"
fi

___scanned=$(($___scanned - 1))
done
done


# report status
printf -- "%s" "${___converted%, }"
return $HestiaKERNEL_ERROR_OK
}
Loading

0 comments on commit 8595e38

Please sign in to comment.