From 7f087e4530ba676628301142f330242ff445e6e2 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 3 Jan 2021 22:07:40 +0000 Subject: sepchar(): add function to seperate characters on given string FossilOrigin-Name: 3c44de3bfd6fbf69658371b2d8cd4d30043dd6f9b568c43ab30291925ebc582e --- src/cpt-lib.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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='' -- cgit v1.2.3