microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
106.96k stars 6.31k forks source link

[Advanced Paste > Paste as JSON] Adding an Ini file parser #33084

Closed htcfreek closed 1 day ago

htcfreek commented 1 month ago

Description of the new feature / enhancement

Currently only xml, CSV and plain text are interpreted. It would be great if also Ini file content can be interpreted for conversation to json.

Scenario when this would be used?

When I need to convert from Ini file to JSON.

Supporting information

We need a small parser like this:

    $ini = @{}
    switch -regex ($iniData)
    {
        “^\[(.+)\]” # Section
        {
            $section = $matches[1]
            $ini[$section] = @{}
        }
        “(.+?)\s*=\s*(.*)” # Key-Value-Pair
        {
            $name,$value = $matches[1..2]
            $ini[$section][$name] = $value
        }
    }

    # Return ($null if no results)
    if ($ini.Count -eq 0) {
        $ini = $null
    }
    return $ini

Written using PowerShell.

htcfreek commented 1 month ago

Notes to me:

htcfreek commented 1 day ago

This is released with PowerToys 0.82.0