Skip to content

Commit

Permalink
init: ported To_Lowercase_{String,Unicode} primitive function
Browse files Browse the repository at this point in the history
Since a number of level-2 Hestia libraries are using string
functions, we have to port the primitive functions into
HestiaKERNEL itself before proceeding. Hence, let's do this.

This patch ports To_Lowercase_{String,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
4 people committed Oct 6, 2024
1 parent 8595e38 commit 8bb57b2
Show file tree
Hide file tree
Showing 11 changed files with 5,211 additions and 13 deletions.
64 changes: 64 additions & 0 deletions init/services/HestiaKERNEL/To_Lowercase_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}\HestiaKERNEL\To_Uppercase_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_Unicode_From_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_String_From_Unicode.ps1"




function HestiaKERNEL-To-Lowercase-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 $___input
}

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


# report status
return HestiaKERNEL-To-String-From-Unicode $___content
}
72 changes: 72 additions & 0 deletions init/services/HestiaKERNEL/To_Lowercase_String.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/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_Lowercase_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_Unicode_From_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_String_From_Unicode.sh"




HestiaKERNEL_To_Lowercase_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_Lowercase_Unicode "$___content")"
if [ "$___content" = "" ]; then
printf -- "%s" "$1"
return $HestiaKERNEL_ERROR_BAD_EXEC
fi


# report status
printf -- "%s" "$(HestiaKERNEL_To_String_From_Unicode "$___content")"
if [ $? -ne $HestiaKERNEL_ERROR_OK ]; then
return $HestiaKERNEL_ERROR_BAD_EXEC
fi

return $HestiaKERNEL_ERROR_OK
}
92 changes: 92 additions & 0 deletions init/services/HestiaKERNEL/To_Lowercase_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_lower.ps1"




function HestiaKERNEL-To-Lowercase-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 = $___unicode.Length - 1
while ($___index -le $___length) {
# get current character
$___current = $___unicode[$___index]


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


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


# process conversion
$___ret = hestiakernel-rune-to-lower $___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_Lowercase_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_lower.sh"

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




HestiaKERNEL_To_Lowercase_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_lower "$___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


# transform back to an actual string
printf -- "%s" "${___converted%, }"
return $HestiaKERNEL_ERROR_OK
}
10 changes: 5 additions & 5 deletions init/services/HestiaKERNEL/To_Uppercase_String.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
# 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"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_Uppercase_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_Unicode_From_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_String_From_Unicode.ps1"



Expand All @@ -50,12 +50,12 @@ function HestiaKERNEL-To-Uppercase-String {
# execute
$___content = HestiaKERNEL-To-Unicode-From-String $___input
if ($___content.Length -eq 0) {
return ""
return $___input
}

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


Expand Down
4 changes: 4 additions & 0 deletions init/services/HestiaKERNEL/To_Uppercase_String.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@ HestiaKERNEL_To_Uppercase_String() {

# report status
printf -- "%s" "$(HestiaKERNEL_To_String_From_Unicode "$___content")"
if [ $? -ne $HestiaKERNEL_ERROR_OK ]; then
return $HestiaKERNEL_ERROR_BAD_EXEC
fi

return $HestiaKERNEL_ERROR_OK
}
Loading

0 comments on commit 8bb57b2

Please sign in to comment.