]> git.plutz.net Git - cgilite/blobdiff - misc.sh
Bugfix: last post element was omitted due to recent changes
[cgilite] / misc.sh
diff --git a/misc.sh b/misc.sh
index 05a3af52385b85547a8952dd0131778e2ce73268..43edfcf70fc88dfc96dfece9036e52ef6851d69b 100755 (executable)
--- a/misc.sh
+++ b/misc.sh
@@ -17,6 +17,9 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with shcgi.  If not, see <http://www.gnu.org/licenses/>. 
 
+BR='
+'
+
 data_dirs(){
   # set up directories for object storage
 
@@ -30,11 +33,28 @@ 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="$(printf %s\\n "$2" | sed -r ':X;s;(^|[^\\])((\\\\)*)/;\1\2\\/;g;tX')"
+                             # ^^ escape only unescaped slash characters for later insertion
   default="$3"
 
   printf %s\\n "${value}" \
-  | sed -rn "2q; /^(${regex})\$/{p;q}; a${default}"
+  | 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 ':X;s;(^|[^\\])((\\\\)*)/;\1\2\\/;g;tX')"
+                             # ^^ escape only unescaped slash characters for later insertion
+  default="$3"
+
+  printf %s\\n "${value}" \
+  | sed -rn "2q; /^(${regex})\$/{bX}; p;q; :X;a${default}
+            "
+}
+
+declare -A item_name
+l10n(){
+  [ -n "${item_name[$1]+x}" ] && printf %s "$item_name[$1]" || printf %s "$1"
 }