From: Paul Hänsch Date: Tue, 14 May 2024 10:31:04 +0000 (+0200) Subject: Squashed 'cgilite/' changes from ad6888a..7f444e3 X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=6fdb619bc3d03f6d4877bbf840483e15f8bb6953;p=confetti Squashed 'cgilite/' changes from ad6888a..7f444e3 7f444e3 new function RXLITERAL() for escaping regex characters git-subtree-dir: cgilite git-subtree-split: 7f444e3275361651eb5e0b89f09fd3afd8113e9f --- diff --git a/storage.sh b/storage.sh index 17ea0d0..5c61df0 100755 --- a/storage.sh +++ b/storage.sh @@ -94,6 +94,21 @@ UNSTRING(){ printf '%s\n' "$out" } +RXLITERAL(){ + # sed -E 's;[].*+?^${}()|\[];\\&;g' + local in out='' + [ $# -gt 0 ] && in="$*" || in="$(cat)" + while [ "$in" ]; do case $in in + [.+^\$\{\}\(\)\[\]\*\?\|\\]*) + out="${out}\\${in%"${in#?}"}"; in="${in#?}"; + ;; + *)out="${out}${in%%[.+^\$\{\}\(\)\[\]\*\?\|\\]*}" + in="${in#"${in%%[.+^\$\{\}\(\)\[\]\*\?\|\\]*}"}" + ;; + esac; done + printf '%s\n' "$out" +} + DBM() { local file="$1" cmd="$2" local k v key value