From 17e9767c01f4faa9863311c6eb0cb38d429c8196 Mon Sep 17 00:00:00 2001 From: "(Holloway) Chew, Kean Ho" Date: Thu, 3 Oct 2024 16:43:37 +0800 Subject: [PATCH] init: ported Get_String_Encoder primitive function 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 Co-authored-by: Galyna, Cory Co-authored-by: (Holloway) Chew, Kean Ho Signed-off-by: (Holloway) Chew, Kean Ho --- .../HestiaKERNEL/Get_String_Encoder.ps1 | 47 ++++++++++++++++ .../HestiaKERNEL/Get_String_Encoder.sh | 53 +++++++++++++++++++ init/services/HestiaKERNEL/Unicode.ps1 | 7 +-- init/services/HestiaKERNEL/Unicode.sh | 7 +-- init/services/HestiaKERNEL/Vanilla.sh.ps1 | 2 + 5 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 init/services/HestiaKERNEL/Get_String_Encoder.ps1 create mode 100644 init/services/HestiaKERNEL/Get_String_Encoder.sh diff --git a/init/services/HestiaKERNEL/Get_String_Encoder.ps1 b/init/services/HestiaKERNEL/Get_String_Encoder.ps1 new file mode 100644 index 0000000..4316e26 --- /dev/null +++ b/init/services/HestiaKERNEL/Get_String_Encoder.ps1 @@ -0,0 +1,47 @@ +# Copyright (c) 2024 (Holloway) Chew, Kean Ho +# +# +# 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} + }} +} diff --git a/init/services/HestiaKERNEL/Get_String_Encoder.sh b/init/services/HestiaKERNEL/Get_String_Encoder.sh new file mode 100644 index 0000000..5ac17e0 --- /dev/null +++ b/init/services/HestiaKERNEL/Get_String_Encoder.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# Copyright (c) 2024 (Holloway) Chew, Kean Ho +# +# +# 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 +} diff --git a/init/services/HestiaKERNEL/Unicode.ps1 b/init/services/HestiaKERNEL/Unicode.ps1 index 1364c39..fd908c2 100644 --- a/init/services/HestiaKERNEL/Unicode.ps1 +++ b/init/services/HestiaKERNEL/Unicode.ps1 @@ -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 diff --git a/init/services/HestiaKERNEL/Unicode.sh b/init/services/HestiaKERNEL/Unicode.sh index 499ab3a..2cefa5f 100644 --- a/init/services/HestiaKERNEL/Unicode.sh +++ b/init/services/HestiaKERNEL/Unicode.sh @@ -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 diff --git a/init/services/HestiaKERNEL/Vanilla.sh.ps1 b/init/services/HestiaKERNEL/Vanilla.sh.ps1 index 4cf9c12..0e565a9 100644 --- a/init/services/HestiaKERNEL/Vanilla.sh.ps1 +++ b/init/services/HestiaKERNEL/Vanilla.sh.ps1 @@ -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" @@ -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"