Brace expansion: Difference between revisions
Content added Content deleted
Line 395: | Line 395: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
{{incorrect|AutoHotkey|Output for edge cases is wrong.}} |
|||
<lang autohotkey>; |
<lang autohotkey>;This one is a lot more simpler than the rest |
||
BraceExp(string, del:="`n") { |
|||
t=~/{Downloads,Pictures}/ *.{jpg,gif,png} ; Note I added a space so the RosettaCode syntax highlighting will work. The AutoHotkey interpreter handles it no problem. |
|||
Loop, Parse, string |
|||
msgbox % expand(t) |
|||
if (A_LoopField = "{") |
|||
t=It{{em,alic}iz,erat}e{d,}, please. |
|||
break |
|||
msgbox % expand(t) |
|||
else |
|||
t={,{,gotta have{ ,\, again\, }}more }cowbell! |
|||
substring .= A_LoopField |
|||
msgbox % expand(t) |
|||
substr := SubStr(string, InStr(string, "{")+1, InStr(string, "}")-InStr(string, "{")-1) |
|||
t={}} some }{,{\\{ edge, edge} \,}{ cases, {here} \\\\\} |
|||
Loop, Parse, substr, `, |
|||
msgbox % expand(t) |
|||
toreturn .= substring . A_LoopField . del |
|||
return toreturn |
|||
} |
|||
Msgbox, % BraceExp("enable_{video,audio}") |
|||
expand(t) { |
|||
Msgbox, % BraceExp("apple {bush,tree}") |
|||
t:=RegExReplace(t, "\\\\", "\!") ; if you want to use these character combinations literally in your string, just switch these susbstitutions to something unicode |
|||
Msgbox, % BraceExp("h{i,ello}") |
|||
,t:=RegExReplace(t, "\\,", "\#") |
|||
Msgbox, % BraceExp("rosetta{code,stone}")</lang> |
|||
,t:=RegExReplace(t, "\\\{", "\@") |
|||
,t:=RegExReplace(t, "\\\}", "\&") |
|||
a=1 |
|||
While a or b |
|||
; expand (braces with multiple commas) which are (apparently inside something else) |
|||
t:=RegExReplace(t, "Sxm)^(.*) ([{,]) ([^{},]*) \{ ([^{},]*) , ([^{},]* , [^{}]*) \} ([^{},]*?) ([},]) (.*)$", "$1$2$3$4$6,$3{$5}$6$7$8", a) |
|||
; expand (braces with single commas) which are (apparently inside something else) |
|||
,t:=RegExReplace(t, "Sxm)^(.*) ([{,]) ([^{},]*) \{ ([^{},]*) , ([^{},]*) \} ([^{},]*?) ([},]) (.*)$", "$1$2$3$4$6,$3$5$6$7$8", b) |
|||
a=1 |
|||
While a or b |
|||
; expand braces with single commas |
|||
t:=RegExReplace(t, "Sxm)^(.*) \{ ([^{},]*) , ([^{},]*) \} (.*)$", "$1$2$4`r`n$1$3$4", a) |
|||
; expand braces with multiple commas |
|||
,t:=RegExReplace(t, "Sxm)^(.*) \{ ([^{},]*) , ([^{},]* , [^{}]*) \} (.*)$", "$1$2$4`r`n$1{$3}$4", b) |
|||
t:=RegExReplace(t, "\\!", "\\") |
|||
,t:=RegExReplace(t, "\\#", "\,") |
|||
,t:=RegExReplace(t, "\\@", "\{") |
|||
,t:=RegExReplace(t, "\\&", "\}") |
|||
Return t |
|||
}</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre>enable_video |
||
enable_audio |
|||
~/Downloads/*.gif |
|||
~/Downloads/*.png |
|||
~/Pictures/*.jpg |
|||
~/Pictures/*.gif |
|||
~/Pictures/*.png |
|||
apple bush |
|||
Itemized, please. |
|||
apple tree |
|||
Itemize, please. |
|||
Italicized, please. |
|||
Italicize, please. |
|||
Iterated, please. |
|||
Iterate, please. |
|||
hi |
|||
cowbell! |
|||
hello |
|||
more cowbell! |
|||
gotta have more cowbell! |
|||
gotta have\, again\, more cowbell! |
|||
rosettacode |
|||
{}} some {\\edge }{ cases, here\\\} |
|||
rosettastone</pre> |
|||
{}} some {\\edgy }{ cases, here\\\}</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |