Skip to content

Commit

Permalink
init: ported Get_String_Encoder primitive function
Browse files Browse the repository at this point in the history
Since level-2 libraries use certain string functions, we have to
port their primitive functions into HestiaKERNEL. Hence, let's
do this.

This patch ports Get_String_Encoder 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
4 people committed Oct 3, 2024
1 parent e477750 commit 17e9767
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 6 deletions.
47 changes: 47 additions & 0 deletions init/services/HestiaKERNEL/Get_String_Encoder.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode.ps1"




function HestiaKERNEL-Get-String-Encoder {
# execute
switch ($OutputEncoding.BodyName.ToUpper()) {
"UTF-8" {
return ${env:HestiaKERNEL_UTF8}
} "UTF-16" {
return ${env:HestiaKERNEL_UTF16BE}
} "UTF-32" {
return ${env:HestiaKERNEL_UTF32BE}
} "default" {
return ${env:HestiaKERNEL_UTF_UNKNOWN}
}}
}
53 changes: 53 additions & 0 deletions init/services/HestiaKERNEL/Get_String_Encoder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/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/Unicode.sh"




HestiaKERNEL_Get_String_Encoder() {
# execute
case "${LANG##*.}" in
"UTF-8")
printf -- "%b" "$HestiaKERNEL_UTF8"
;;
"UTF-16")
printf -- "%b" "$HestiaKERNEL_UTF16BE"
;;
"UTF-32")
printf -- "%b" "$HestiaKERNEL_UTF32BE"
;;
*)
printf -- "%b" "$HestiaKERNEL_UTF_UNKNOWN"
;;
esac
return 0
}
7 changes: 4 additions & 3 deletions init/services/HestiaKERNEL/Unicode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@


# UTF encoding type
${env:HestiaKERNEL_UTF8} = 0
${env:HestiaKERNEL_UTF8} = 0 # default
${env:HestiaKERNEL_UTF8_BOM} = 1
${env:HestiaKERNEL_UTF16BE} = 2
${env:HestiaKERNEL_UTF16BE} = 2 # default
${env:HestiaKERNEL_UTF16BE_BOM} = 3
${env:HestiaKERNEL_UTF16LE} = 4
${env:HestiaKERNEL_UTF16LE_BOM} = 5
${env:HestiaKERNEL_UTF32BE} = 6
${env:HestiaKERNEL_UTF32BE} = 6 # default
${env:HestiaKERNEL_UTF32BE_BOM} = 7
${env:HestiaKERNEL_UTF32LE} = 8
${env:HestiaKERNEL_UTF32LE_BOM} = 9
${env:HestiaKERNEL_UTF_UNKNOWN} = 255
7 changes: 4 additions & 3 deletions init/services/HestiaKERNEL/Unicode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@


# UTF encoding type
HestiaKERNEL_UTF8=0
HestiaKERNEL_UTF8=0 # default
HestiaKERNEL_UTF8_BOM=1
HestiaKERNEL_UTF16BE=2
HestiaKERNEL_UTF16BE=2 # default
HestiaKERNEL_UTF16BE_BOM=3
HestiaKERNEL_UTF16LE=4
HestiaKERNEL_UTF16LE_BOM=5
HestiaKERNEL_UTF32BE=6
HestiaKERNEL_UTF32BE=6 # default
HestiaKERNEL_UTF32BE_BOM=7
HestiaKERNEL_UTF32LE=8
HestiaKERNEL_UTF32LE_BOM=9
HestiaKERNEL_UTF_UNKNOWN=255
2 changes: 2 additions & 0 deletions init/services/HestiaKERNEL/Vanilla.sh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null
# Windows POWERSHELL Codes #
################################################################################
. "${env:LIBS_HESTIA}\HestiaKERNEL\Error_Codes.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Get_String_Encoder.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Run_Parallel_Sentinel.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_Unicode_From_String.ps1"
Expand All @@ -54,6 +55,7 @@ RUN_AS_POWERSHELL
# Unix Main Codes #
################################################################################
. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Get_String_Encoder.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Run_Parallel_Sentinel.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_Unicode_From_String.sh"
Expand Down

0 comments on commit 17e9767

Please sign in to comment.