Skip to content

Commit

Permalink
init: fixed Trim_Left_String primitive function bug
Browse files Browse the repository at this point in the history
There were some minor performance bugs from Trim_Left_String
primitive function. Hence, let's fix it.

This patch fixes Trim_Left_String primitive function bug
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 9, 2024
1 parent 0c9d835 commit dd6616f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 20 deletions.
3 changes: 0 additions & 3 deletions init/services/HestiaKERNEL/String/Trim_Left_String.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ function HestiaKERNEL-Trim-Left-String {
}

$___content = HestiaKERNEL-Trim-Left-Unicode $___content $___chars
if ($___content.Length -eq 0) {
return $___input
}


# report status
Expand Down
9 changes: 0 additions & 9 deletions init/services/HestiaKERNEL/String/Trim_Left_String.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,7 @@ HestiaKERNEL_Trim_Left_String() {
fi

___content="$(HestiaKERNEL_Trim_Left_Unicode "$___content" "$___chars")"
if [ "$___content" = "" ]; then
printf -- "%s" "$1"
return $HestiaKERNEL_ERROR_BAD_EXEC
fi

___content="$(HestiaKERNEL_To_String_From_Unicode "$___content")"
if [ "$___content" = "" ]; then
printf -- "%s" "$1"
return $HestiaKERNEL_ERROR_BAD_EXEC
fi
printf -- "%s" "$___content"


Expand Down
10 changes: 3 additions & 7 deletions init/services/HestiaKERNEL/Unicode/Trim_Left_Unicode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ HestiaKERNEL_Trim_Left_Unicode() {


# execute
## IMPORTANT NOTICE
## POSIX Shell's UNIX regex cannot recognize anything outside Latin-1
## script. Therefore, manual algorithmic handling is required.
___content_unicode="$1"
___charset_unicode="$2"
___converted=""
while [ ! "$___content_unicode" = "" ]; do
# get current character
___current="${___content_unicode%%, *}"
Expand All @@ -50,7 +46,7 @@ HestiaKERNEL_Trim_Left_Unicode() {

# get char from charset character
___charset_list="$___charset_unicode"
___mismatched=0
___mismatched=0 ## assume mismatched by default
while [ ! "$___charset_list" = "" ]; do
___char="${___charset_list%%, *}"
___charset_list="${___charset_list#"$___char"}"
Expand All @@ -68,13 +64,13 @@ HestiaKERNEL_Trim_Left_Unicode() {

# It's a mismatch - append the rest and bail out
if [ $___mismatched -eq 0 ]; then
___converted="${___current}, ${___content_unicode}"
___content_unicode="${___current}, ${___content_unicode}"
break
fi
done


# report status
printf -- "%s" "${___converted%, }"
printf -- "%s" "${___content_unicode%, }"
return $HestiaKERNEL_ERROR_OK
}
1 change: 0 additions & 1 deletion init/services/HestiaKERNEL/Unicode/Trim_Right_Unicode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ HestiaKERNEL_Trim_Right_Unicode() {
# execute
___content_unicode="$1"
___charset_unicode="$2"
___converted=""
while [ ! "$___content_unicode" = "" ]; do
# get current character
___current="${___content_unicode##*, }"
Expand Down

0 comments on commit dd6616f

Please sign in to comment.