Skip to content

Commit

Permalink
init: ported Is_Punctuation_{String,Unicode} primitive functions
Browse files Browse the repository at this point in the history
Since a number of level 1 Hestia libraries use string functions,
we have to port its primitive ones into HestiaKERNEL library package.
Hence, let's do this.

This patch ports Is_Punctuation_{String,Unicode} primitive function
into HestiaKERNEL library 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
4 people committed Nov 5, 2024
1 parent 55ef361 commit 4fd7117
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 8 deletions.
32 changes: 32 additions & 0 deletions init/services/HestiaKERNEL/Is_Punctuation_String.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Error_Codes.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Punctuation_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\To_Unicode_From_String.ps1"




function HestiaKERNEL-Is-Punctuation-String {
param (
[string]$___rune
)


# validate input
if ($(HestiaKERNEL-To-Unicode-From-String $___rune) -ne ${env:HestiaKERNEL_ERROR_OK}) {
return ${env:HestiaKERNEL_ERROR_DATA_INVALID}
}


# execute
return HestiaKERNEL-Is-Punctuation-Unicode [uint32]$___rune[0]
}
33 changes: 33 additions & 0 deletions init/services/HestiaKERNEL/Is_Punctuation_String.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Punctuation_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/To_Unicode_From_String.sh"




HestiaKERNEL_Is_Punctuation_String() {
#___rune="$1"


# execute
___unicode="$(HestiaKERNEL_To_Unicode_From_String "$1")"
if [ $? -ne $HestiaKERNEL_ERROR_OK ]; then
printf -- "%d" $HestiaKERNEL_ERROR_DATA_INVALID
return $HestiaKERNEL_ERROR_DATA_INVALID
fi


printf -- "%d" "$(HestiaKERNEL_Is_Punctuation_Unicode "${___unicode%%, *}")"
return $?
}
54 changes: 54 additions & 0 deletions init/services/HestiaKERNEL/Is_Punctuation_Unicode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Error_Codes.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Number.ps1"




function HestiaSTRING-Is-Punctuation-Unicode {
param (
[uint32]$___unicode
)


# validate input
if ($(HestiaKERNEL-Is-Number $___unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) {
return ${env:HestiaKERNEL_ERROR_DATA_INVALID}
}


# execute
if (
(($___unicode -ge 0x0021) -and ($___unicode -le 0x002F)) -or
(($___unicode -ge 0x003A) -and ($___unicode -le 0x0040)) -or
(($___unicode -ge 0x007B) -and ($___unicode -le 0x007E)) -or
(($___unicode -ge 0x00A1) -and ($___unicode -le 0x00BF)) -or
(($___unicode -ge 0x2000) -and ($___unicode -le 0x206F)) -or
(($___unicode -ge 0x2E00) -and ($___unicode -le 0x2E7F)) -or
(($___unicode -ge 0x3000) -and ($___unicode -le 0x303F)) -or
(($___unicode -ge 0x12400) -and ($___unicode -le 0x1247F)) -or
(($___unicode -ge 0x16FE0) -and ($___unicode -le 0x16FFF))
) {
# Latin-1 Script (0x0021-0x002F; 0x003A-0x0040)
# Latin-1 Suppliment Script (0x00A0-0x00BF)
# General Punctuation Script (0x2000-0x206F)
# Supplemental Punctuation Script (0x2E00-0x2E7F)
# CJK Symbols and Punctuation Script (0x3000-0x303F)
# Cuneiform Number and Punctuation Script (0x12400-0x1247F)
# Ideographic Symbols and Punctuation Script (0x16FE0-0x16FFF)
return ${env:HestiaKERNEL_ERROR_OK}
}


# report status
return ${env:HestiaKERNEL_ERROR_DATA_INVALID}
}
54 changes: 54 additions & 0 deletions init/services/HestiaKERNEL/Is_Punctuation_Unicode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Number.sh"




HestiaKERNEL_Is_Punctuation_Unicode() {
#___unicode="$1"


# validate input
if [ "$(HestiaKERNEL_Is_Number "$1")" -ne $HestiaKERNEL_ERROR_OK ]; then
printf -- "%d" $HestiaKERNEL_ERROR_DATA_INVALID
return $HestiaKERNEL_ERROR_DATA_INVALID
fi


# execute
if ([ $1 -ge 33 ] && [ $1 -le 47 ]) ||
([ $1 -ge 58 ] && [ $1 -le 64 ]) ||
([ $1 -ge 123 ] && [ $1 -le 126 ]) ||
([ $1 -ge 161 ] && [ $1 -le 191 ]) ||
([ $1 -ge 8192 ] && [ $1 -le 8303 ]) ||
([ $1 -ge 11776 ] && [ $1 -le 11903 ]) ||
([ $1 -ge 12288 ] && [ $1 -le 12351 ]) ||
([ $1 -ge 74752 ] && [ $1 -le 74879 ]) ||
([ $1 -ge 94176 ] && [ $1 -le 94207 ]); then
# Latin-1 Script (0x0021-0x002F; 0x003A-0x0040)
# Latin-1 Suppliment Script (0x00A0-0x00BF)
# General Punctuation Script (0x2000-0x206F)
# Supplemental Punctuation Script (0x2E00-0x2E7F)
# CJK Symbols and Punctuation Script (0x3000-0x303F)
# Cuneiform Number and Punctuation Script (0x12400-0x1247F)
# Ideographic Symbols and Punctuation Script (0x16FE0-0x16FFF)
printf -- "%d" $HestiaKERNEL_ERROR_OK
return $HestiaKERNEL_ERROR_OK
fi


# report status
printf -- "%d" $HestiaKERNEL_ERROR_DATA_INVALID
return $HestiaKERNEL_ERROR_DATA_INVALID
}
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Is_Whitespace_String.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ function HestiaKERNEL-Is-Whitespace-String {


# execute
return HestiaKERNEL-Is-Whitespace-Unicode $___rune
return HestiaKERNEL-Is-Whitespace-Unicode [uint32]$___rune[0]
}
2 changes: 1 addition & 1 deletion init/services/HestiaKERNEL/Is_Whitespace_String.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ HestiaKERNEL_Is_Whitespace_String() {
return $HestiaKERNEL_ERROR_DATA_INVALID
fi

printf -- "%d" "$(HestiaKERNEL_Is_Whitespace_Unicode "$___unicode")"
printf -- "%d" "$(HestiaKERNEL_Is_Whitespace_Unicode "${___unicode%%, *}")"
return $?
}
6 changes: 3 additions & 3 deletions init/services/HestiaKERNEL/Is_Whitespace_Unicode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Error_Codes.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Number.ps1"



Expand All @@ -21,8 +21,8 @@ function HestiaKERNEL-Is-Whitespace-Unicode {


# validate input
if ($(HestiaKERNEL-Is-Unicode $___unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) {
return ${env:HestiaKERNEL_ERROR_DATA_EMPTY}
if ($(HestiaKERNEL-Is-Number $___unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) {
return ${env:HestiaKERNEL_ERROR_DATA_INVALID}
}


Expand Down
6 changes: 3 additions & 3 deletions init/services/HestiaKERNEL/Is_Whitespace_Unicode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Number.sh"



Expand All @@ -20,8 +20,8 @@ HestiaKERNEL_Is_Whitespace_Unicode() {


# validate input
if [ "$(HestiaKERNEL_Is_Unicode "$1")" -ne $HestiaKERNEL_ERROR_OK ]; then
printf -- ""
if [ "$(HestiaKERNEL_Is_Number "$1")" -ne $HestiaKERNEL_ERROR_OK ]; then
printf -- "%d" $HestiaKERNEL_ERROR_DATA_INVALID
return $HestiaKERNEL_ERROR_DATA_INVALID
fi

Expand Down
4 changes: 4 additions & 0 deletions init/services/HestiaKERNEL/Vanilla.sh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ echo \" <<'RUN_AS_POWERSHELL' >/dev/null # " | Out-Null
. "${env:LIBS_HESTIA}\HestiaKERNEL\Error_Codes.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Get_String_Encoder.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Array_Number.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Punctuation_String.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Punctuation_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Unicode.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_UTF.ps1"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Whitespace_String.ps1"
Expand Down Expand Up @@ -75,6 +77,8 @@ RUN_AS_POWERSHELL
. "${LIBS_HESTIA}/HestiaKERNEL/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Get_String_Encoder.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Array_Number.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Punctuation_String.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Punctuation_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Unicode.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_UTF.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Whitespace_String.sh"
Expand Down
12 changes: 12 additions & 0 deletions init/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ ${env:LIBS_HESTIA} = "${env:LIBS_UPSCALER}\services"
. "${env:LIBS_UPSCALER}\services\i18n\report-success.ps1"

### TEST ZONE
. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Whitespace_String.ps1"
Write-Host "$(HestiaKERNEL-Is-Whitespace-String " ")"
Write-Host "$(HestiaKERNEL-Is-Whitespace-String "m")"
Write-Host "$(HestiaKERNEL-Is-Whitespace-String "m ")"
Write-Host "$(HestiaKERNEL-Is-Whitespace-String " m")"

. "${env:LIBS_HESTIA}\HestiaKERNEL\Is_Punctuation_String.ps1"
Write-Host "$(HestiaKERNEL-Is-Punctuation-String ",")"
Write-Host "$(HestiaKERNEL-Is-Punctuation-String "m")"
Write-Host "$(HestiaKERNEL-Is-Punctuation-String "m,")"
Write-Host "$(HestiaKERNEL-Is-Punctuation-String ",m")"

. "${env:LIBS_HESTIA}\HestiaKERNEL\Trim_Right_String.ps1"
Write-Host "$(HestiaKERNEL-Trim-Right-String "e你feeeff你你aerg aegE你F" "E你F")"
. "${env:LIBS_HESTIA}\HestiaKERNEL\Trim_Left_String.ps1"
Expand Down
13 changes: 13 additions & 0 deletions init/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ LIBS_HESTIA="${LIBS_UPSCALER}/services"
. "${LIBS_UPSCALER}/services/i18n/report-success.sh"

### TEST ZONE
. "${LIBS_HESTIA}/HestiaKERNEL/Is_Whitespace_String.sh"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Whitespace_String " ")"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Whitespace_String "m")"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Whitespace_String "m ")"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Whitespace_String " m")"


. "${LIBS_HESTIA}/HestiaKERNEL/Is_Punctuation_String.sh"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Punctuation_String ",")"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Punctuation_String "m")"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Punctuation_String "m,")"
1>&2 printf -- "%d\n" "$(HestiaKERNEL_Is_Punctuation_String ",m")"

. "${LIBS_HESTIA}/HestiaKERNEL/Trim_Right_String.sh"
1>&2 printf -- "%s\n" "$(HestiaKERNEL_Trim_Right_String "e你feeeff你你aerg aegE你F" "E你F")"
. "${LIBS_HESTIA}/HestiaKERNEL/Trim_Left_String.sh"
Expand Down

0 comments on commit 4fd7117

Please sign in to comment.