:X $bY; N; bX; :Y s;^.*$;\n&\n;;
# === Join continuing lines, strip trailing CRs ===
- s;\r\n[ \t];;g;
- s;\r\n;\n;g;
+ s;\r*\n[ \t];;g;
+ s;\r*\n;\n;g;
# === turn property names to upper case, strip group names ===
s;\n([^;:\.\n]+\.)([^;:\n]+);\n\2;g;
pdi_value(){
local card="${BR}$1" name="$2" cnt="${3:-1}"
- while [ $cnt -gt 0 ]; do
+ while [ "$cnt" -gt 0 ]; do
[ "${card#*${BR}${name};*:}" = "$card" ] && return 1
card="${card#*${BR}${name};*:}"
cnt=$((cnt - 1))
done
printf %s\\n "${card%%${BR}*}"
}
+
+pdi_update_value(){
+ local card="${BR}$1" name="$2" cnt="$3" val="$4"
+ while [ "$cnt" -gt 0 ]; do
+ if [ "${card#*${BR}${name};*:}" = "${card}" ]; then
+ printf '%s\n%s;:' "${card%${BR}END:VCARD*}" "${name}"
+ card="${BR}END;:VCARD"
+ break;
+ else
+ printf '%s\n%s;' "${card%%${BR}${name};*}" "${name}"
+ card="${card#*${BR}${name};}"
+ printf '%s:' "${card%%:*}"
+ card="${card#*:}"
+ fi
+ cnt=$((cnt - 1))
+ done
+ printf '%s\n' "$val"
+ printf '%s\n' "${card#*${BR}}"
+}