Brace expansion: Difference between revisions
Content added Content deleted
(Added Elixir) |
(→{{header|Ruby}}: easy to understand.) |
||
Line 1,911: | Line 1,911: | ||
c = s[0] |
c = s[0] |
||
break if depth>0 and (c == ',' or c == '}') |
break if depth>0 and (c == ',' or c == '}') |
||
if c == '{' |
if c == '{' and x = getgroup(s[1..-1], depth+1) |
||
out = out.product(x[0]).map{|a,b| a+b} |
|||
s = x[1] |
|||
⚫ | |||
⚫ | |||
s |
s, c = s[1..-1], c + s[1] if c == '\\' and s.size > 1 |
||
⚫ | |||
next |
|||
⚫ | |||
end |
end |
||
s, c = s[1..-1], c + s[1] if c == '\\' and s.size > 1 |
|||
out, s = out.map{|a| a+c}, s[1..-1] |
|||
end |
end |
||
return out, s |
return out, s |
||
Line 1,931: | Line 1,928: | ||
break if s.empty? |
break if s.empty? |
||
out += g |
out += g |
||
case s[0] |
|||
return out, s[1..-1] |
when '}' then return (comma ? out : out.map{|a| "{#{a}}"}), s[1..-1] |
||
when ',' then comma, s = true, s[1..-1] |
|||
end |
end |
||
comma, s = true, s[1..-1] if s[0] == ',' |
|||
end |
end |
||
nil |
|||
end |
end |
||