From 6fdb619bc3d03f6d4877bbf840483e15f8bb6953 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 14 May 2024 12:31:04 +0200 Subject: [PATCH] Squashed 'cgilite/' changes from ad6888a..7f444e3 7f444e3 new function RXLITERAL() for escaping regex characters git-subtree-dir: cgilite git-subtree-split: 7f444e3275361651eb5e0b89f09fd3afd8113e9f --- storage.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 -- 2.39.2