aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-01-03 22:07:40 +0000
committermerakor <cem@ckyln.com>2021-01-03 22:07:40 +0000
commit7f087e4530ba676628301142f330242ff445e6e2 (patch)
treecac464c1ed57ee06f9e97f6f15b42e3efbb2341e /src
parent67ca267cd28e82a90bdf8abd38b6e1c25ffb59e9 (diff)
downloadcpt-7f087e4530ba676628301142f330242ff445e6e2.tar.gz
sepchar(): add function to seperate characters on given string
FossilOrigin-Name: 3c44de3bfd6fbf69658371b2d8cd4d30043dd6f9b568c43ab30291925ebc582e
Diffstat (limited to 'src')
-rw-r--r--src/cpt-lib.in15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/cpt-lib.in b/src/cpt-lib.in
index 5e5e7b4..cc4938b 100644
--- a/src/cpt-lib.in
+++ b/src/cpt-lib.in
@@ -45,6 +45,21 @@ trap_set() {
esac
}
+sepchar() (
+ # Seperate every character on the given string without resorting to external
+ # processes.
+ [ "$1" ] || return 0; str=$1; set --
+ while [ "$str" ]; do
+ str_tmp=$str
+ for i in $(_seq $(( ${#str} - 1 ))); do
+ str_tmp=${str_tmp%?}
+ done
+ set -- "$@" "$str_tmp"
+ str=${str#$str_tmp}
+ done
+ printf '%s\n' "$@"
+)
+
_seq() (
# Pure shell counter meant to be used in 'for' loops.
i=0 buf=''