X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=storage.sh;h=fd7582057e112f2ec582e6ede8d7dd1995ce2a66;hp=a6b6b436a947cea57b3bf684df5e8c67caa9cb66;hb=d214859aadb31a565718da69754ad2573fa3f917;hpb=a301c53cc6f28dde4fa2f80d5785f7988542e327 diff --git a/storage.sh b/storage.sh index a6b6b43..fd75820 100755 --- a/storage.sh +++ b/storage.sh @@ -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 "$*"; } \ + | printf %s "$*" |sed -r ':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 -r "$UNSTRING" }