mirror of https://github.com/dyne/zuper.git
strtok tokenizer
This commit is contained in:
parent
0690c9881c
commit
c865ff0deb
32
zuper
32
zuper
|
|
@ -257,6 +257,31 @@ _ztmp_destructor() {
|
|||
arrs+=(tmpfiles)
|
||||
destruens+=(_ztmp_destructor)
|
||||
|
||||
# tokenizer, works only with one char length delimiters
|
||||
# saves everything in global array tok=()
|
||||
arrs+=(tok)
|
||||
strtok() {
|
||||
fn "strtok $*"
|
||||
_string="$1"
|
||||
_delim="$2"
|
||||
req=(_string _delim)
|
||||
ckreq || return $?
|
||||
|
||||
tok=()
|
||||
f=0
|
||||
for c in {1..${#_string}}; do
|
||||
if [[ "${_string[(e)$c]}" == "$_delim" ]]; then
|
||||
# check if not empty
|
||||
t=${_string[(e)$(($f + 1)),$(($c - 1))]}
|
||||
[[ "$t" == "" ]] || tok+=($t)
|
||||
# save last found
|
||||
f=$c
|
||||
fi
|
||||
done
|
||||
# add last token
|
||||
t=${_string[(e)$(($f + 1)),$c]}
|
||||
[[ "$t" == "" ]] || tok+=($t)
|
||||
}
|
||||
|
||||
# optional: define zkv=1 on source
|
||||
|
||||
|
|
@ -530,6 +555,13 @@ s/"/\"/g
|
|||
|
||||
# {{{ Config
|
||||
|
||||
# This is not a full config parser, but its a mechanism to read single
|
||||
# sections of configuration files that are separated using various
|
||||
# syntax methods. The only method supported is now org-mode whose
|
||||
# sections start with #+ . It fills in the global array
|
||||
# $config_section which can be read out to a file or interpreted in
|
||||
# memory, whatever syntax it may contain.
|
||||
|
||||
vars+=(config_section_type)
|
||||
arrs+=(config_section)
|
||||
config_section_type=org-mode
|
||||
|
|
|
|||
Loading…
Reference in New Issue