X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=misc.sh;h=54c3dc67f68c83ed21ab45907bf295f6d0a4f2eb;hp=05a3af52385b85547a8952dd0131778e2ce73268;hb=203fb52bb5b1462dc65678208a9a0eb5f97a0180;hpb=ae8b8df6f76b8e9f1976fc02e82bd4db6e3e31a6 diff --git a/misc.sh b/misc.sh index 05a3af5..54c3dc6 100755 --- a/misc.sh +++ b/misc.sh @@ -38,3 +38,20 @@ validate(){ printf %s\\n "${value}" \ | sed -rn "2q; /^(${regex})\$/{p;q}; a${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 + default="$3" + + printf %s\\n "${value}" \ + | sed -rn "2q; /^(${regex})\$/{bd}; p;q; :d;a${default}" +} + +declare -A item_name +l10n(){ + [ -n "${item_name[$1]+x}" ] && printf %s "$item_name[$1]" || printf %s "$1" +}