[GNC] ANNOUNCE: GnuCash 5.10 Released
AP
gnucash at inml.grue.cc
Wed Dec 18 23:31:03 EST 2024
On Wed, Dec 18, 2024 at 08:11:29PM -0800, John Ralls wrote:
> > I asked the Lord God AI (as I'm not a powershell user) and it came up with this:
> >
> > --- 8<---
> > # Define an array of strings with non-version related text before the version numbers
> > $versionStrings = @(
> > 'ProductA v1.2.3',
> > 'ProductB v1.10.0',
> > 'ProductC v1.3.5',
> > 'ProductD v2.0.0'
> > )
> >
> > # Extract the version part using a regular expression and sort by the extracted version
> > $sortedVersions = $versionStrings | Sort-Object {
> > if ($_ -match 'v([\d\.]+)$') {
> > [version]$matches[1]
> > }
> > }
> >
> > # Display the sorted versions
> > $sortedVersions
> > --- 8<---
> >
> > Don't know how right it is but if it's not right in and of itself then, maybe, it's right enough to get you most of the way there. :)
> >
>
> You don’t show the output, but the result of the regex match is still a string so I think it will still sort lexically, i.e. 1.10.0, 1.2.3, 1.3.5, 2.0.0.
That's cos I don't do powershell. :)
That said I copied and pasted and the result was:
ProductA v1.2.3
ProductC v1.3.5
ProductB v1.10.0
ProductD v2.0.0
The [version] thing, according to the AI, apparently tells it to sort as a version string. The regex is there to remove the prefix because the string has to be pure version.
> This S-O suggests using a function called System.Version:
> https://stackoverflow.com/questions/711107/sorting-powershell-versions.
> Dunno if it works on two-digit version numbers. My default
> approach in most languages would be to do two captures,
> ‘(\d+).(\d+)$’ and cast each to int and do a two-level sort.
> https://stackoverflow.com/questions/71232189/how-to-sort-multilevel-list
> suggests how to do the multi-level sort part.
That may work until someone does a really minor release and you get 5.10.1. Humans like to break things. :)
If you treat it as a version it should just work[tm].
Andrew
More information about the gnucash-user
mailing list