Brace expansion: Difference between revisions

m (→‎{{header|Perl 6}}: Combine into a single file for ease of testing)
Line 1,659:
]
}</lang>
 
 
=={{header|Julia}}==
{{trans|Python}} <lang>
function getitem(s, depth=0)
out = [""]
while s != ""
c = s[1]
if depth > 0 && (c == ',' || c == '}')
return out, s
elseif c == '{'
x = getgroup(s[2:end], depth+1)
if x != ""
out = [a * b for a in out, b in x[1]]
s = x[2]
continue
end
elseif c == '\\' && length(s) > 1
s = s[2:end]
c = c * s[2]
end
out = [a * c for a in out]
s = s[2:end]
end
return out, s
end
function getgroup(s, depth)
out, comma = "", false
while s != ""
g, s = getitem(s, depth)
if s == ""
break
end
out = vcat([out...], [g...])
if s[1] == '}'
if comma
return out, s[2:end]
end
return ["{" * a * "}" for a in out], s[2:end]
end
if s[1] == ','
comma, s = true, s[2:end]
end
end
return ""
end
 
const teststrings = [raw"~/{Downloads,Pictures}/*.{jpg,gif,png}",
raw"It{{em,alic}iz,erat}e{d,}, please.",
raw"{,{,gotta have{ ,\, again\, }}more }cowbell!",
raw"{}} some }{,{\\\\{ edge, edge} \,}{ cases, {here} \\\\\\\\\}'''"]
for s in teststrings
println("\n", s, "\n--------------------------------------------")
for ans in getitem(s)[1]
println(ans)
end
end
</lang> {{output}} <pre>
~/{Downloads,Pictures}/*.{jpg,gif,png}
--------------------------------------------
~/Downloads/*.jpg
~/Pictures/*.jpg
~/Downloads/*.gif
~/Pictures/*.gif
~/Downloads/*.png
~/Pictures/*.png
 
It{{em,alic}iz,erat}e{d,}, please.
--------------------------------------------
Itemized, please.
Italicized, please.
Iterated, please.
Itemize, please.
Italicize, please.
Iterate, please.
 
{,{,gotta have{ ,\, again\, }}more }cowbell!
--------------------------------------------
cowbell!
more cowbell!
gotta have more cowbell!
gotta have\ again\ more cowbell!
 
{}} some }{,{\\\\{ edge, edge} \,}{ cases, {here} \\\\\\\\\}'''
--------------------------------------------
{}} some }{,{\\\{ edge \}}{ cases, {here} \\\\\\\\\''''
{}} some }{,{\\\{ edge \}}{ cases, {here} \\\\\\\\\''''
</pre>
 
 
4,108

edits