]> git.plutz.net Git - confetti/commitdiff
Squashed 'cgilite/' changes from ad6888a..7f444e3
authorPaul Hänsch <paul@plutz.net>
Tue, 14 May 2024 10:31:04 +0000 (12:31 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 14 May 2024 10:31:04 +0000 (12:31 +0200)
7f444e3 new function RXLITERAL() for escaping regex characters

git-subtree-dir: cgilite
git-subtree-split: 7f444e3275361651eb5e0b89f09fd3afd8113e9f

storage.sh

index 17ea0d051eaf27233f8b5cd96f7396974c7a87f1..5c61df0a041e75df0e1ee0e81aa0c09078cdabc1 100755 (executable)
@@ -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