New-RangeString.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
function New-RangeString { [Diagnostics.CodeAnalysis.SuppressMessageAttribute( "PSUseShouldProcessForStateChangingFunctions", "", Justification = "Creates in-memory object only." )] [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [int] $Width , [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [int] $LeftIndex , [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [int] $RightIndex , [Parameter()] [ValidateNotNullOrEmpty()] [string] $LeftIndicator = '|' , [Parameter()] [ValidateNotNullOrEmpty()] [string] $RightIndicator = '|' ) Write-Debug ('[{0}] Width={1} LeftIndex={2} RightIndex={3}' -f $MyInvocation.MyCommand, $Width, $LeftIndex, $RightIndex) if ($LeftIndex -lt 0) { $LeftIndex = 1 $LeftIndicator = '<' } if ($LeftIndex -eq 0) { $LeftIndex = 1 } Write-Debug ('[{0}] Width={1} LeftIndex={2} RightIndex={3}' -f $MyInvocation.MyCommand, $Width, $LeftIndex, $RightIndex) $line = ' ' * ($LeftIndex - 1) + $LeftIndicator if ($RightIndex -gt $Width) { $RightIndex = $Width $RightIndicator = '>' } Write-Debug ('[{0}] Width={1} LeftIndex={2} RightIndex={3}' -f $MyInvocation.MyCommand, $Width, $LeftIndex, $RightIndex) if ($RightIndex -gt $LeftIndex) { $line += '-' * ($RightIndex - $LeftIndex - 1) } $line += $RightIndicator $line } |