#!/bin/zsh
-# Copyright 2014 - 2018 Paul Hänsch
+# Copyright 2014 - 2018, 2023 Paul Hänsch
#
# This file is part of Confetti.
#
BR='
'
-
-unescape() {
- local unescape='s;(^(\\\\)*|[^\\](\\\\)*)\\n;\1\n;g; s;\\(.);\1;g'
- if [ $# -eq 0 ]; then
- sed -E "$unescape"
- else
- printf %s "$*" \
- | sed -E "$unescape"
- fi
-}
+unescape(){
+ local in out=''
+ [ $# -gt 0 ] && in="$*" || in="$(cat)"
+ while [ "$in" ]; do case $in in
+ \\\\*) out="${out}\\"; in="${in#\\\\}" ;;
+ \\n*) out="${out}${BR}"; in="${in#\\n}" ;;
+ \\*) in="${in#\\}" ;;
+ *) out="${out}${in%%[\\]*}"; in="${in#"${in%%[\\]*}"}" ;;
+ esac; done
+ printf '%s\n' "$out"
+ }
pdi_load() {
# normalise PDI file for processing with pdi_* functions