generated from ChewKeanHo/AutomataCI
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init: ported To_Uppercase_{String,Unicode} primitive function
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
1 parent
c0d6fa6
commit 8595e38
Showing
10 changed files
with
5,262 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.