]> git.plutz.net Git - cgilite/blobdiff - storage.sh
allow configuration of session timeout, make timestamp variable reusable
[cgilite] / storage.sh
index a6b6b436a947cea57b3bf684df5e8c67caa9cb66..10a802950465c813001a3aa27f95f2f4a22dd1b7 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright 2018 Paul Hänsch
+# Copyright 2018, 2019 Paul Hänsch
 #
 # This is a file format helper, part of CGIlite.
 # 
@@ -63,27 +63,31 @@ RELEASE(){
   fi
 }
 
+STRING='
+  s;\\;\\\\;g;
+  s;\n;\\n;g;
+  s;\t;\\t;g;
+  s;\r;\\r;g;
+  s;\+;\\+;g;
+  s; ;+;g;
+'
+
 STRING(){
-  printf %s "$*" |sed -r '
-    :X; $!{N;bX;}
-    s;\\;\\\\;g;
-    s;\n;\\n;g;
-    s;\t;\\t;g;
-    s;\r;\\r;g;
-    s;\+;\\+;g;
-    s; ;+;g;
-  '
+  { [ $# -eq 0 ] && cat || printf %s "$*"; } \
+  | sed -E ':X; $!{N;bX;}'"$STRING"
 }
 
+UNSTRING='
+  :UNSTRING_X
+  s;((^|[^\\])(\\\\)*)\\n;\1\n;g;
+  s;((^|[^\\])(\\\\)*)\\t;\1\t;g;
+  s;((^|[^\\])(\\\\)*)\\r;\1\r;g;
+  s;((^|[^\\])(\\\\)*)\+;\1 ;g;
+  tUNSTRING_X;
+  s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
+  s;\\\\;\\;g;
+'
 UNSTRING(){
-  printf %s "$*" |sed -r '
-    :X
-    s;((^|[^\\])(\\\\)*)\\n;\1\n;g;
-    s;((^|[^\\])(\\\\)*)\\t;\1\t;g;
-    s;((^|[^\\])(\\\\)*)\\r;\1\r;g;
-    s;((^|[^\\])(\\\\)*)\+;\1 ;g;
-    tX;
-    s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
-    s;\\\\;\\;g;
-  '
+  { [ $# -eq 0 ] && cat || printf %s "$*"; } \
+  | sed -E "$UNSTRING"
 }