forked from hollowaykeanho/Upscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init: ported Has_{String,Unicode} primitive function
Since there are a number of level 1 libraries using the string function, we have to port its primitive ones into HestiaKERNEL library. Let's do this. This patch ports Has_{String,Unicode} primitive function into HestiaKERNEL library 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
d9ac552
commit a3c289b
Showing
6 changed files
with
220 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,31 @@ | ||
# 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\Unicode\Has_Unicode.ps1" | ||
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\To_Unicode_From_String.ps1" | ||
|
||
|
||
|
||
|
||
function HestiaKERNEL-Has-String { | ||
param ( | ||
[string]$___input, | ||
[string]$___target | ||
) | ||
|
||
|
||
# execute | ||
$___content = HestiaKERNEL-To-Unicode-From-String $___input | ||
$___chars = HestiaKERNEL-To-Unicode-From-String $___prefix | ||
|
||
|
||
# report status | ||
return HestiaKERNEL-Has-Unicode $___content $___chars | ||
} |
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,31 @@ | ||
#!/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/Unicode/Has_Unicode.sh" | ||
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/To_Unicode_From_String.sh" | ||
|
||
|
||
|
||
|
||
HestiaKERNEL_Has_String() { | ||
#___input="$1" | ||
#___target="$2" | ||
|
||
|
||
# execute | ||
___content="$(HestiaKERNEL_To_Unicode_From_String "$1")" | ||
___chars="$(HestiaKERNEL_To_Unicode_From_String "$2")" | ||
printf -- "%d" "$(HestiaKERNEL_Has_Unicode "$___content" "$___chars")" | ||
|
||
|
||
# report status | ||
return $? | ||
} |
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,59 @@ | ||
# 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\Errors\Error_Codes.ps1" | ||
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Is_Unicode.ps1" | ||
|
||
|
||
|
||
|
||
function HestiaKERNEL-Has-Unicode { | ||
param ( | ||
[uint32[]]$___content_unicode, | ||
[uint32[]]$___target_unicode | ||
) | ||
|
||
|
||
# validate input | ||
if ( | ||
($(HestiaKERNEL-Is-Unicode $___content_unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) -or | ||
($(HestiaKERNEL-Is-Unicode $___target_unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) | ||
) { | ||
return ${env:HestiaKERNEL_ERROR_ENTITY_EMPTY} | ||
} | ||
|
||
if ($___target_unicode.Length -gt $___content_unicode.Length) { | ||
return ${env:HestiaKERNEL_ERROR_DATA_MISMATCHED} - # guarenteed mismatched by length | ||
} | ||
|
||
|
||
# execute | ||
$___target_index = 0 | ||
$___target_length = $___target_unicode.Length - 1 | ||
for ($___index = 0; $___index -le $___content_unicode.Length - 1; $___index++) { | ||
if ($___target_index -ge $___target_length) { | ||
# PASS - complete match | ||
return ${env:HestiaKERNEL_ERROR_OK} | ||
} | ||
|
||
if ($___content_unicode[$___index] -eq $___target_unicode[$___target_index]) { | ||
# PASS - char matched | ||
$___target_index += 1 | ||
continue | ||
} | ||
|
||
# FAIL - char mismatched | ||
$___target_index = 0 | ||
} | ||
|
||
|
||
# report status | ||
return ${env:HestiaKERNEL_ERROR_DATA_MISMATCHED} | ||
} |
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,73 @@ | ||
#!/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/Errors/Error_Codes.sh" | ||
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Is_Unicode.sh" | ||
|
||
|
||
|
||
|
||
HestiaKERNEL_Has_Unicode() { | ||
#___content_unicode="$1" | ||
#___target_unicode="$2" | ||
|
||
|
||
# validate input | ||
if [ $(HestiaKERNEL_Is_Unicode "$1") -ne $HestiaKERNEL_ERROR_OK ]; then | ||
printf -- "%s" "$HestiaKERNEL_ERROR_ENTITY_EMPTY" | ||
return $HestiaKERNEL_ERROR_ENTITY_EMPTY | ||
fi | ||
|
||
if [ $(HestiaKERNEL_Is_Unicode "$2") -ne $HestiaKERNEL_ERROR_OK ]; then | ||
printf -- "%s" "$HestiaKERNEL_ERROR_DATA_EMPTY" | ||
return $HestiaKERNEL_ERROR_DATA_EMPTY | ||
fi | ||
|
||
|
||
# execute | ||
___content_unicode="$1" | ||
___target_unicode="$2" | ||
while [ ! "$___content_unicode" = "" ]; do | ||
# get current character | ||
___current="${___content_unicode%%, *}" | ||
___content_unicode="${___content_unicode#"$___current"}" | ||
if [ "${___content_unicode%"${___content_unicode#?}"}" = "," ]; then | ||
___content_unicode="${___content_unicode#, }" | ||
fi | ||
|
||
|
||
# get target character | ||
___target="${___target_unicode%%, *}" | ||
___target_unicode="${___target_unicode#"$___target"}" | ||
if [ "${___target_unicode%"${___target_unicode#?}"}" = "," ]; then | ||
___target_unicode="${___target_unicode#, }" | ||
fi | ||
|
||
|
||
# FAIL - reset $___target_unicode | ||
if [ ! "$___current" = "$___target" ]; then | ||
___target_unicode="$2" | ||
continue | ||
fi | ||
|
||
|
||
# PASS - fully matched | ||
if [ "$___current" = "$___target" ] && [ "$___target_unicode" = "" ]; then | ||
printf -- "%d" "$HestiaKERNEL_ERROR_OK" | ||
return $HestiaKERNEL_ERROR_OK | ||
fi | ||
done | ||
|
||
|
||
# report status | ||
printf -- "%d" "$HestiaKERNEL_ERROR_DATA_MISMATCHED" | ||
return $HestiaKERNEL_ERROR_DATA_MISMATCHED | ||
} |
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
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