From fa143f64a78895dd3cf1e43be6841f009c008337 Mon Sep 17 00:00:00 2001 From: Couleur <82747632+couleurm@users.noreply.github.com> Date: Mon, 8 Jan 2024 16:21:14 +0100 Subject: [PATCH] PsIni: add -delimiter and comments --- helpers/PsInI/Get-IniContent.ps1 | 9 ++++++--- helpers/PsInI/Out-IniFile.ps1 | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/helpers/PsInI/Get-IniContent.ps1 b/helpers/PsInI/Get-IniContent.ps1 index 11cab38..1681193 100644 --- a/helpers/PsInI/Get-IniContent.ps1 +++ b/helpers/PsInI/Get-IniContent.ps1 @@ -70,11 +70,14 @@ # Lines starting with the characters provided will be rendered as comments. # Default: ";" [Char[]] - $CommentChar = @(";"), + $CommentChar = @(";", "#", ":", "/"), # Remove lines determined to be comments from the resulting dictionary. [Switch] - $IgnoreComments + $IgnoreComments, + + [String] + $delimiter = '=' ) Begin { @@ -89,7 +92,7 @@ $commentRegex = "^\s*([$($CommentChar -join '')].*)$" $sectionRegex = "^\s*\[(.+)\]\s*$" - $keyRegex = "^\s*(.+?)\s*=\s*(['`"]?)(.*)\2\s*$" + $keyRegex = "^\s*(.+?)\s*$delimiter\s*(['`"]?)(.*)\2\s*$" Write-Debug ("commentRegex is {0}." -f $commentRegex) } diff --git a/helpers/PsInI/Out-IniFile.ps1 b/helpers/PsInI/Out-IniFile.ps1 index c52cd3c..5de18c6 100644 --- a/helpers/PsInI/Out-IniFile.ps1 +++ b/helpers/PsInI/Out-IniFile.ps1 @@ -103,7 +103,10 @@ Function Out-IniFile { # # Adds an extra linebreak between Sections [Switch] - $Pretty + $Pretty, + + [String] + $delimiter = '=' ) Begin { @@ -161,9 +164,8 @@ Function Out-IniFile { } } - $delimiter = '=' if ($Loose) { - $delimiter = ' = ' + $delimiter = "$delimiter " } # Splatting Parameters