X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=misc.sh;h=96393099598a53b5cc3350a9d04234f2d2ec4598;hp=adc879b3091474e24cbb765a001d211717c1b6d8;hb=1a1d111199b770c092e1b16a7e03568d3d911b79;hpb=7baad0fc1db205353fe7414d358b43a015ef5848 diff --git a/misc.sh b/misc.sh index adc879b..9639309 100755 --- a/misc.sh +++ b/misc.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014, 2015 Paul Hänsch +# Copyright 2014 - 2017 Paul Hänsch # # This file is part of shcgi. # @@ -17,6 +17,9 @@ # You should have received a copy of the GNU Affero General Public License # along with shcgi. If not, see . +BR=' +' + data_dirs(){ # set up directories for object storage @@ -30,28 +33,22 @@ data_dirs(){ validate(){ # print value if value matches regex; otherwise print default value="$1" - regex="$(printf %s\\n "$2" \ - | sed -r 's;(^|[^\\]+)((\\\\)+)/;\1\2\\/;g; s;(^|[^\\])/;\1\\/;g; s;(^|[^\\]+)((\\\\)+)/;\1\2\\/;g; s;(^|[^\\])/;\1\\/;g;' - )" # ^^ escape only unescaped slash characters for later insertion + regex="$2" default="$3" - printf %s\\n "${value}" \ - | sed -rn "2q; /^(${regex})\$/{p;q}; a${default}" + printf %s "${value%%${BR}*}" |grep -xE "$regex" || printf %s "$default" } invalidate(){ # print default if value matches regex; otherwise print value value="$1" - regex="$(printf %s\\n "$2" \ - | sed -r 's;(^|[^\\]+)((\\\\)+)/;\1\2\\/;g; s;(^|[^\\])/;\1\\/;g; s;(^|[^\\]+)((\\\\)+)/;\1\2\\/;g; s;(^|[^\\])/;\1\\/;g;' - )" # ^^ escape only unescaped slash characters for later insertion + regex="$2" default="$3" - - printf %s\\n "${value}" \ - | sed -rn "2q; /^(${regex})\$/{bd}; p;q; :d;a${default}" + + printf %s "${value%%${BR}*}" |grep -qxE "$regex" && printf %s "$default" || printf %s "${value%%${BR}*}" } declare -A item_name l10n(){ - [ -n "$item_name[$1]+x" ] && printf %s "$item_name[$1]" || printf %s "$1" + [ -n "${item_name[$1]+x}" ] && printf %s "$item_name[$1]" || printf %s "$1" }