From 9c0dedbe71799e2968cca664300fab01e93d482f Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 11 Nov 2016 18:32:21 +0000 Subject: [PATCH] parsing and processing of aggregated values, split values, vcard escapes svn path=/trunk/; revision=142 --- pages/cards.sh | 62 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/pages/cards.sh b/pages/cards.sh index 3f0be4a..f6142df 100755 --- a/pages/cards.sh +++ b/pages/cards.sh @@ -111,7 +111,8 @@ vcf_parse() { y;abcdefghijklmnopqrstuvwxyz;ABCDEFGHIJKLMNOPQRSTUVWXYZ; G; s;\n;;; - + # === strip trailing CR (but keep CRs in property value) === + s;\r$;;; # === Normalise various known vendor properties === s;^X-MS-CARDPICTURE(\;|:);PHOTO\1;; @@ -175,16 +176,59 @@ vcf_parse() { if [ -z "$key" ]; then eval "$line" else - values[${key}]="${value//\\r\\n/$BR}" - for t in ${(k)tag}; do - values[${key}_${t}]="${tag[$t]}" + printf '%s\n' "$value" |sed -rn ' + :X + s;((^|[^\\])(\\\\)*),;\1\n;g; + tX; + s;\\,;,;g; + p + ' \ + | while read -r val; do + while [ -n "${values[$key$n]+x}" ]; do n=$((${n=-1} + 1)); done + if printf '%s\n' "$val" |grep -qE '((^|[^\\])(\\\\)*)\;'; then + m=0 + values[${key}${n}]="${val}" + printf '%s\n' "$val" |sed -rn ' + :X + s;((^|[^\\])(\\\\)*)\;;\1\n;g; + tX; + s;\\\;;\;;g; + p + ' \ + | while read -r v; do + values[${key}${n}+${m}]="$( + printf %s\\n "${v}" \ + | sed -rn ' + :X + s;((^|[^\\])(\\\\)*)\\n;\1\n;g; + tX; + s;\\\\;\\;g; + p + ' + )" + m=$(($m + 1)) + done + else + values[${key}${n}]="$( + printf %s\\n "${val}" \ + | sed -rn ' + :X + s;((^|[^\\])(\\\\)*)\\n;\1\n;g; + tX; + s;\\\;;\;;g; + s;\\\\;\\;g; + p + ' + )" + fi + for t in ${(k)tag}; do + values[${key}${n}_${t}]="${tag[$t]}" + done done + eval "$line" - if [ -n "$values[$key]" ]; then - n=0 - while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done - key=$key$n - fi + unset n + while [ -n "${values[$key$n]+x}" ]; do n=$((${n=-1} + 1)); done unset value unset tag fi -- 2.39.2