about summary refs log tree commit diff
path: root/Src/subst.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2012-04-22 18:10:42 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2012-04-22 18:10:42 +0000
commit5eb53bf88d3153510f0a5304e921b46419fe5721 (patch)
tree944578b22dcca9b8a6d3e1b211dfd04386ced7a6 /Src/subst.c
parent19fe2dcc03d6f3c418e738061e46d0ae013c2550 (diff)
downloadzsh-5eb53bf88d3153510f0a5304e921b46419fe5721.tar.gz
zsh-5eb53bf88d3153510f0a5304e921b46419fe5721.tar.xz
zsh-5eb53bf88d3153510f0a5304e921b46419fe5721.zip
30431 with typo in _typeset fix:
add ${...:|...} and ${...:*...} operators, as documented
Diffstat (limited to 'Src/subst.c')
-rw-r--r--Src/subst.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/Src/subst.c b/Src/subst.c
index dac536f14..82645ccfa 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2876,6 +2876,49 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags)
 	    }
 	    break;
 	}
+    } else if (inbrace && (*s == '|' || *s == Bar ||
+			   *s == '*' || *s == Star)) {
+	int intersect = (*s == '*' || *s == Star);
+	char **compare = getaparam(++s), **ap, **apsrc;
+	if (compare) {
+	    HashTable ht = newuniqtable(arrlen(compare)+1);
+	    int present;
+	    for (ap = compare; *ap; ap++)
+		(void)addhashnode2(ht, *ap, (HashNode)
+				   zhalloc(sizeof(struct hashnode)));
+	    if (!vunset && isarr) {
+		if (!copied) {
+		    aval = arrdup(aval);
+		    copied = 1;
+		}
+		for (ap = apsrc = aval; *apsrc; apsrc++) {
+		    untokenize(*apsrc);
+		    present = (gethashnode2(ht, *apsrc) != NULL);
+		    if (intersect ? present : !present) {
+			if (ap != apsrc) {
+			    *ap = *apsrc;
+			}
+			ap++;
+		    }
+		}
+		*ap = NULL;
+	    } else {
+		if (vunset) {
+		    if (unset(UNSET)) {
+			*idend = '\0';
+			zerr("%s: parameter not set", idbeg);
+			deletehashtable(ht);
+			return NULL;
+		    }
+		    val = dupstring("");
+		} else {
+		    present = (gethashnode2(ht, val) != NULL);
+		    if (intersect ? !present : present)
+			val = dupstring("");
+		}
+	    }
+	    deletehashtable(ht);
+	}
     } else {			/* no ${...=...} or anything, but possible modifiers. */
 	/*
 	 * Handler ${+...}.  TODO: strange, why do we handle this only