generated from ChewKeanHo/AutomataCI
-
Notifications
You must be signed in to change notification settings - Fork 26
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_UTF32_From_Unicode primitive function
Since there are a number of level-2 libraries are using some string functions, we have to port them into HestiaKERNEL library. This patch ports To_UTF32_From_Unicode primitive function into 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
3dc03ef
commit 73c2723
Showing
3 changed files
with
228 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Copyright (c) 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. | ||
function HestiaKERNEL-To-UTF32-From-Unicode { | ||
param ( | ||
[uint32[]]$___content, | ||
[string]$___bom, | ||
[string]$___endian | ||
) | ||
|
||
|
||
# validate input | ||
if ($___content.Length -eq 0) { | ||
return [uint8[]]@() | ||
} | ||
|
||
|
||
# execute | ||
[System.Collections.Generic.List[uint8]]$___converted = @() | ||
if ($___bom -ne "") { | ||
switch ($___endian) { | ||
{ $_ -in "le", "LE", "little", "Little", "LITTLE" } { | ||
# UTF32LE BOM - 0xFF, 0xFE, 0x00, 0x00 | ||
$null = $___converted.Add(0xFF) | ||
$null = $___converted.Add(0xFE) | ||
$null = $___converted.Add(0x00) | ||
$null = $___converted.Add(0x00) | ||
} default { | ||
# UTF32BE BOM (default) - 0x00, 0x00, 0xFE, 0xFF | ||
$null = $___converted.Add(0x00) | ||
$null = $___converted.Add(0x00) | ||
$null = $___converted.Add(0xFE) | ||
$null = $___converted.Add(0xFF) | ||
}} | ||
} | ||
|
||
foreach ($___char in $___content) { | ||
# convert to UTF-32 bytes list | ||
## 0x00000 - 0x10000 - 0x10FFFF (surrogate pair region) | ||
switch ($___endian) { | ||
{ $_ -in "le", "LE", "little", "Little", "LITTLE" } { | ||
$___register = $___char -band 0xFF | ||
$null = $___converted.Add($___register) | ||
|
||
$___register = $___char -band 0xFF00 | ||
$___register = $___register -shr 8 | ||
$null = $___converted.Add($___register) | ||
|
||
___register=$(($___char -band 0xFF0000)) | ||
___register=$(($___register -shr 16)) | ||
$null = $___converted.Add($___register) | ||
|
||
___register=$(($___char -band 0xFF000000)) | ||
___register=$(($___register -shr 24)) | ||
$null = $___converted.Add($___register) | ||
} default { | ||
___register=$(($___char -band 0xFF000000)) | ||
___register=$(($___register -shr 24)) | ||
$null = $___converted.Add($___register) | ||
|
||
___register=$(($___char -band 0xFF0000)) | ||
___register=$(($___register -shr 16)) | ||
$null = $___converted.Add($___register) | ||
|
||
___register=$(($___char -band 0xFF00)) | ||
___register=$(($___register -shr 8)) | ||
$null = $___converted.Add($___register) | ||
|
||
___register=$(($___register -band 0xFF)) | ||
$null = $___converted.Add($___register) | ||
}} | ||
} | ||
|
||
|
||
# report status | ||
return [uint8[]]$___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,123 @@ | ||
#!/bin/sh | ||
# Copyright (c) 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" | ||
|
||
|
||
|
||
|
||
HestiaKERNEL_To_UTF32_From_Unicode() { | ||
#___content="$1" | ||
#___bom="$2" | ||
#___endian="$3" | ||
|
||
|
||
# validate input | ||
if [ "$1" = "" ]; then | ||
printf -- "" | ||
return $HestiaKERNEL_ERROR_DATA_EMPTY | ||
fi | ||
|
||
case "$1" in | ||
*[!0123456789\ \,]*) | ||
printf -- "" | ||
return $HestiaKERNEL_ERROR_DATA_INVALID | ||
;; | ||
esac | ||
|
||
|
||
# execute | ||
___converted="" | ||
if [ ! "$2" = "" ]; then | ||
case "$3" in | ||
"le"|"LE"|"little"|"Little"|"LITTLE") | ||
# UTF32LE BOM - 0xFF, 0xFE, 0x00, 0x00 | ||
___converted="255, 254, 0, 0" | ||
;; | ||
*) | ||
# UTF32BE BOM (default) - 0x00, 0x00, 0xFE, 0xFF | ||
___converted="0, 0, 254, 255" | ||
;; | ||
esac | ||
fi | ||
|
||
___content="$1" | ||
while [ ! "$___content" = "" ]; do | ||
# get current character decimal | ||
___char="${___content%%, *}" | ||
___content="${___content#"$___char"}" | ||
if [ "${___content%"${___content#?}"}" = "," ]; then | ||
___content="${___content#, }" | ||
fi | ||
|
||
|
||
# convert to UTF-32 bytes list | ||
# IMPORTANT NOTICE | ||
# (1) using single code-point algorithm (not the 2 16-bits). | ||
case "$3" in | ||
"le"|"LE"|"little"|"Little"|"LITTLE") | ||
___register=$(($___char & 0xFF)) | ||
___converted="${___converted}$(printf -- "%d" "$___register"), " | ||
|
||
___register=$(($___char & 0xFF00)) | ||
___register=$(($___char >> 8)) | ||
___converted="${___converted}$(printf -- "%d" "$___register"), " | ||
|
||
___register=$(($___char & 0xFF0000)) | ||
___register=$(($___char >> 16)) | ||
___converted="${___converted}$(printf -- "%d" "$___register"), " | ||
|
||
___register=$(($___char & 0xFF000000)) | ||
___register=$(($___char >> 24)) | ||
___converted="${___converted}$(printf -- "%d" "$___register"), " | ||
;; | ||
*) | ||
___register=$(($___char & 0xFF000000)) | ||
___register=$(($___char >> 24)) | ||
___converted="${___converted}$(printf -- "%d" "$___register"), " | ||
|
||
___register=$(($___char & 0xFF0000)) | ||
___register=$(($___char >> 16)) | ||
___converted="${___converted}$(printf -- "%d" "$___register"), " | ||
|
||
___register=$(($___char & 0xFF00)) | ||
___register=$(($___char >> 8)) | ||
___converted="${___converted}$(printf -- "%d" "$___register"), " | ||
|
||
___register=$(($___char & 0xFF)) | ||
___converted="${___converted}$(printf -- "%d" "$___register"), " | ||
;; | ||
esac | ||
done | ||
|
||
|
||
# report status | ||
printf -- "%s" "${___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