Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
55
Task/Brace-expansion/PowerShell/brace-expansion-1.psh
Normal file
55
Task/Brace-expansion/PowerShell/brace-expansion-1.psh
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
function Expand-Braces ( [string]$String )
|
||||
{
|
||||
$Escaped = $False
|
||||
$Stack = New-Object System.Collections.Stack
|
||||
$ClosedBraces = $BracesToParse = $Null
|
||||
|
||||
ForEach ( $i in 0..($String.Length-1) )
|
||||
{
|
||||
Switch ( $String[$i] )
|
||||
{
|
||||
'\' {
|
||||
$Escaped = -not $Escaped
|
||||
break
|
||||
}
|
||||
|
||||
'{' {
|
||||
If ( -not $Escaped ) { $Stack.Push( [pscustomobject]@{ Delimiters = @( $i ) } ) }
|
||||
}
|
||||
|
||||
',' {
|
||||
If ( -not $Escaped -and $Stack.Count ) { $Stack.Peek().Delimiters += $i }
|
||||
}
|
||||
|
||||
'}' {
|
||||
If ( -not $Escaped -and $Stack.Count )
|
||||
{
|
||||
$Stack.Peek().Delimiters += $i
|
||||
$ClosedBraces = $Stack.Pop()
|
||||
If ( $ClosedBraces.Delimiters.Count -gt 2 )
|
||||
{
|
||||
$BracesToParse = $ClosedBraces
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default { $Escaped = $False }
|
||||
}
|
||||
}
|
||||
|
||||
If ( $BracesToParse )
|
||||
{
|
||||
$Start = $String.Substring( 0, $BracesToParse.Delimiters[0] )
|
||||
$End = $String.Substring( $BracesToParse.Delimiters[-1] + 1 )
|
||||
|
||||
ForEach ( $i in 0..($BracesToParse.Delimiters.Count-2) )
|
||||
{
|
||||
$Option = $String.Substring( $BracesToParse.Delimiters[$i] + 1, $BracesToParse.Delimiters[$i+1] - $BracesToParse.Delimiters[$i] - 1 )
|
||||
Expand-Braces ( $Start + $Option + $End )
|
||||
}
|
||||
}
|
||||
Else
|
||||
{
|
||||
$String
|
||||
}
|
||||
}
|
||||
14
Task/Brace-expansion/PowerShell/brace-expansion-2.psh
Normal file
14
Task/Brace-expansion/PowerShell/brace-expansion-2.psh
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
$TestStrings = @(
|
||||
'It{{em,alic}iz,erat}e{d,}, please.'
|
||||
'~/{Downloads,Pictures}/*.{jpg,gif,png}'
|
||||
'{,{,gotta have{ ,\, again\, }}more }cowbell!'
|
||||
'{}} some }{,{\\{ edge, edge} \,}{ cases, {here} \\\\\}'
|
||||
)
|
||||
|
||||
ForEach ( $String in $TestStrings )
|
||||
{
|
||||
''
|
||||
$String
|
||||
'------'
|
||||
Expand-Braces $String
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue