Anonymous user
Read a configuration file: Difference between revisions
→Using Switch -Regex: Using regex \s
(→{{header|PowerShell}}: Using Switch -Regex) |
(→Using Switch -Regex: Using regex \s) |
||
Line 3,430:
=== Using Switch -Regex ===
<lang PowerShell>
Function Houdini-Value ([String]$_Text) {▼
$__Aux = $_Text.Trim(" `t")▼
If ($__Aux.Length -eq 0) {▼
$__Aux = $true▼
} ElseIf ($__Aux.Contains(',')) {▼
$__Aux = $__Aux.Split(',') |▼
ForEach-Object {▼
If ($PSItem.Trim(" `t").Length -ne 0) {▼
$PSItem.Trim(" `t")▼
}▼
}▼
}▼
Return $__Aux▼
Function Read-ConfigurationFile {
[CmdletBinding()]
Line 3,463 ⟶ 3,448:
)
Begin {
▲ Function Houdini-Value ([String]$_Text) {
▲ If ($__Aux.Length -eq 0) {
▲ $__Aux = $true
▲ } ElseIf ($__Aux.Contains(',')) {
▲ $__Aux = $__Aux.Split(',') |
▲ ForEach-Object {
}
▲ }
▲ }
▲ Return $__Aux
}
▲ }
Process {
$__Configuration = [Ordered]@{}
# Config equivalent pattern
# Select-String -Pattern '^
Switch -Regex -File $_LiteralPath {
'^
Write-Verbose -Message "v$('
Write-Verbose -Message $Matches[0]
Continue
Line 3,479 ⟶ 3,481:
Write-Verbose -Message $Matches[0]
$__Name,$__Value = $Matches[1..2]
$__Configuration[$__Name.Trim(
Continue
}
'^
Write-Verbose -Message '↓← ← ← ← ← ← ← ← ← ← space or tab pattern or only name'
Write-Verbose -Message $Matches[0]
$__Name,$__Value = $Matches[
$__Configuration[$__Name.Trim(
Continue
}
|