generated from ChewKeanHo/AutomataCI
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init: ported Trim_Whitespace_Left_{String,Unicode} primitive function
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 Trim_Whitespace_Left_{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
1 parent
790db8a
commit 7611373
Showing
7 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
init/services/HestiaKERNEL/String/Trim_Whitespace_Left_String.ps1
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,37 @@ | ||
# 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\String\To_String_From_Unicode.ps1" | ||
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Trim_Whitespace_Left_Unicode.ps1" | ||
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\To_Unicode_From_String.ps1" | ||
|
||
|
||
|
||
|
||
function HestiaKERNEL-Trim-Whitespace-Left-String { | ||
param ( | ||
[string]$___input | ||
) | ||
|
||
|
||
# validate input | ||
if ($___input -eq "") { | ||
return $___input | ||
} | ||
|
||
|
||
# execute | ||
$___content = HestiaKERNEL-To-Unicode-From-String $___input | ||
$___content = HestiaKERNEL-Trim-Whitespace-Left-Unicode $___content | ||
|
||
|
||
# report status | ||
return HestiaKERNEL-To-String-From-Unicode $___content | ||
} |
44 changes: 44 additions & 0 deletions
44
init/services/HestiaKERNEL/String/Trim_Whitespace_Left_String.sh
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,44 @@ | ||
#!/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/String/To_String_From_Unicode.sh" | ||
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Trim_Whitespace_Left_Unicode.sh" | ||
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/To_Unicode_From_String.sh" | ||
|
||
|
||
|
||
|
||
HestiaKERNEL_Trim_Whitespace_Left_String() { | ||
#___content="$1" | ||
|
||
|
||
# validate input | ||
if [ "$1" = "" ]; then | ||
printf -- "%s" "$1" | ||
return $HestiaKERNEL_ERROR_ENTITY_EMPTY | ||
fi | ||
|
||
|
||
# execute | ||
___content="$(HestiaKERNEL_To_Unicode_From_String "$1")" | ||
if [ "$___content" = "" ]; then | ||
printf -- "%s" "$1" | ||
return $HestiaKERNEL_ERROR_DATA_INVALID | ||
fi | ||
|
||
___content="$(HestiaKERNEL_Trim_Whitespace_Left_Unicode "$___content")" | ||
printf -- "%s" "$(HestiaKERNEL_To_String_From_Unicode "$___content")" | ||
|
||
|
||
# report status | ||
return $HestiaKERNEL_ERROR_OK | ||
} |
54 changes: 54 additions & 0 deletions
54
init/services/HestiaKERNEL/Unicode/Trim_Whitespace_Left_Unicode.ps1
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,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\Errors\Error_Codes.ps1" | ||
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Is_Unicode.ps1" | ||
. "${env:LIBS_HESTIA}\HestiaKERNEL\Unicode\Is_Whitespace_Unicode.ps1" | ||
|
||
|
||
|
||
|
||
function HestiaKERNEL-Trim-Whitespace-Left-Unicode { | ||
param ( | ||
[uint32[]]$___content_unicode | ||
) | ||
|
||
|
||
# validate input | ||
if ($(HestiaKERNEL-Is-Unicode $___content_unicode) -ne ${env:HestiaKERNEL_ERROR_OK}) { | ||
return $___content_unicode | ||
} | ||
|
||
|
||
# execute | ||
$___index = 0 | ||
for (; $___index -le $___content_unicode.Length - 1; $___index++) { | ||
# get current character | ||
$___current = $___content_unicode[$___index] | ||
|
||
|
||
# skip if matched | ||
if ($(HestiaKERNEL-Is-Whitespace-Unicode $___current) -eq ${env:HestiaKERNEL_ERROR_OK}) { | ||
continue | ||
} | ||
|
||
|
||
# mismatched so stop the scan | ||
break | ||
} | ||
|
||
if ($___index -ge $___content_unicode.Length - 1) { | ||
return [uint32[]]@() | ||
} | ||
|
||
|
||
# report status | ||
return [uint32[]]$___content_unicode[$___index..($___content_unicode.Length - 1)] | ||
} |
56 changes: 56 additions & 0 deletions
56
init/services/HestiaKERNEL/Unicode/Trim_Whitespace_Left_Unicode.sh
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,56 @@ | ||
#!/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" | ||
. "${LIBS_HESTIA}/HestiaKERNEL/Unicode/Is_Whitespace_Unicode.sh" | ||
|
||
|
||
|
||
|
||
HestiaKERNEL_Trim_Whitespace_Left_Unicode() { | ||
#___content_unicode="$1" | ||
|
||
|
||
# validate input | ||
if [ $(HestiaKERNEL_Is_Unicode "$1") -ne $HestiaKERNEL_ERROR_OK ]; then | ||
printf -- "%s" "$1" | ||
return $HestiaKERNEL_ERROR_ENTITY_EMPTY | ||
fi | ||
|
||
|
||
# execute | ||
___content_unicode="$1" | ||
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 | ||
|
||
|
||
# skip if matched | ||
if [ $(HestiaKERNEL_Is_Whitespace_Unicode "$___current") -eq $HestiaKERNEL_ERROR_OK ]; then | ||
continue | ||
fi | ||
|
||
|
||
# mismatched so stop the scan | ||
___content_unicode="${___current}, ${___content_unicode}" | ||
break | ||
done | ||
|
||
|
||
# report status | ||
printf -- "%s" "$___content_unicode" | ||
return $HestiaKERNEL_ERROR_OK | ||
} |
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
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