Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Go to Heaven for the climate, Hell for the company." -- Mark Twain


devel / comp.lang.c / Re: Embedded numbers sorting function (begging post)

SubjectAuthor
* Re: Embedded numbers sorting function (begging post)Bart
`* Re: Embedded numbers sorting function (begging post)Malcolm McLean
 +* Re: Embedded numbers sorting function (begging post)Scott Lurndal
 |`- Re: Embedded numbers sorting function (begging post)Malcolm McLean
 +* Re: Embedded numbers sorting function (begging post)John Forkosh
 |`* Re: Embedded numbers sorting function (begging post)Kenny McCormack
 | `* Re: Embedded numbers sorting function (begging post)Malcolm McLean
 |  +- Re: Embedded numbers sorting function (begging post)Kaz Kylheku
 |  `- Re: Embedded numbers sorting function (begging post)John Forkosh
 `* Re: Embedded numbers sorting function (begging post)Jorgen Grahn
  `* Re: Embedded numbers sorting function (begging post)Malcolm McLean
   `* Re: Embedded numbers sorting function (begging post)Jorgen Grahn
    +* Re: Embedded numbers sorting function (begging post)Malcolm McLean
    |`* Re: Embedded numbers sorting function (begging post)John Forkosh
    | `- Re: Embedded numbers sorting function (begging post)Kaz Kylheku
    `- Re: Embedded numbers sorting function (begging post)Manfred

1
Re: Embedded numbers sorting function (begging post)

<sv3711$k46$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20514&group=comp.lang.c#20514

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Tue, 22 Feb 2022 17:37:37 +0000
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <sv3711$k46$1@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 22 Feb 2022 17:37:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ee52d1e1733deb61d1d6a1580f71a1b2";
logging-data="20614"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dSWqbOGQHDEt9A1bXq/1RUM+lPM4IIiU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:uExlWm0HPO2WpI30Ks61ijzyYOs=
In-Reply-To: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
 by: Bart - Tue, 22 Feb 2022 17:37 UTC

On 22/02/2022 15:27, Malcolm McLean wrote:
> Anyone got a string comparison function handy which compares strings intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?

There are all sorts of problems with this. What is it you're really
trying to do; what does the data look like?

Simplest might be to just extract the first numeric field and test that
as a number, but this needs to be a decision made on all strings being
compared, rather than case by case.

Or do you have a specification for such a function?

Re: Embedded numbers sorting function (begging post)

<643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20515&group=comp.lang.c#20515

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:adf:fa92:0:b0:1e7:e760:49dd with SMTP id h18-20020adffa92000000b001e7e76049ddmr20494991wrr.99.1645552310698;
Tue, 22 Feb 2022 09:51:50 -0800 (PST)
X-Received: by 2002:a37:ad0f:0:b0:5f1:70cc:362 with SMTP id
f15-20020a37ad0f000000b005f170cc0362mr16468227qkm.187.1645552310237; Tue, 22
Feb 2022 09:51:50 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.128.87.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 22 Feb 2022 09:51:50 -0800 (PST)
In-Reply-To: <sv3711$k46$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:f5ae:5e9d:c8ee:6c75;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:f5ae:5e9d:c8ee:6c75
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com> <sv3711$k46$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
Subject: Re: Embedded numbers sorting function (begging post)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Tue, 22 Feb 2022 17:51:50 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Tue, 22 Feb 2022 17:51 UTC

On Tuesday, 22 February 2022 at 17:38:03 UTC, Bart wrote:
> On 22/02/2022 15:27, Malcolm McLean wrote:
> > Anyone got a string comparison function handy which compares strings intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
> There are all sorts of problems with this. What is it you're really
> trying to do; what does the data look like?
>
> Simplest might be to just extract the first numeric field and test that
> as a number, but this needs to be a decision made on all strings being
> compared, rather than case by case.
>
> Or do you have a specification for such a function?
>
I'm writing a UI, with graphic "profiles". The user draws a "profile", then grabs it, and gives it a name. The default names go "Profile 1", "Profile 2" and so on.
I don't know how many profiles the user will create. Obviously not millions, but low thousands would be humanly possible. I don't know what sort of names
he'll give the profiles, but I opted for things like "Noise1", "Noise2" to describe similar profiles. I sort the names in various list boxes, so user can find
the prfile he wants by scrolling through the list box and looking alphabetically.

Re: Embedded numbers sorting function (begging post)

<qA9RJ.26451$kuda.26153@fx12.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20516&group=comp.lang.c#20516

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx12.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Embedded numbers sorting function (begging post)
Newsgroups: comp.lang.c
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com> <sv3711$k46$1@dont-email.me> <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
Lines: 22
Message-ID: <qA9RJ.26451$kuda.26153@fx12.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 22 Feb 2022 18:04:06 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 22 Feb 2022 18:04:06 GMT
X-Received-Bytes: 2257
 by: Scott Lurndal - Tue, 22 Feb 2022 18:04 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>On Tuesday, 22 February 2022 at 17:38:03 UTC, Bart wrote:
>> On 22/02/2022 15:27, Malcolm McLean wrote:
>> > Anyone got a string comparison function handy which compares strings intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
>> There are all sorts of problems with this. What is it you're really
>> trying to do; what does the data look like?
>>
>> Simplest might be to just extract the first numeric field and test that
>> as a number, but this needs to be a decision made on all strings being
>> compared, rather than case by case.
>>
>> Or do you have a specification for such a function?
>>
>I'm writing a UI, with graphic "profiles". The user draws a "profile", then grabs it, and gives it a name. The default names go "Profile 1", "Profile 2" and so on.
>I don't know how many profiles the user will create. Obviously not millions, but low thousands would be humanly possible. I don't know what sort of names
>he'll give the profiles, but I opted for things like "Noise1", "Noise2" to describe similar profiles. I sort the names in various list boxes, so user can find
>the prfile he wants by scrolling through the list box and looking alphabetically.

Well, you could create your own locale and use the strcoll function.

Or you can do a normal C locale sort in descending order instead of
ascending order if you really want 2 to collate ahead of 1.

Re: Embedded numbers sorting function (begging post)

<a5735cad-e01f-4305-b3ec-5aa16983b0dbn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20517&group=comp.lang.c#20517

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6000:15cb:b0:1ea:7db2:f5bb with SMTP id y11-20020a05600015cb00b001ea7db2f5bbmr4642829wry.709.1645553707611;
Tue, 22 Feb 2022 10:15:07 -0800 (PST)
X-Received: by 2002:a05:6214:21ac:b0:42c:2844:aa93 with SMTP id
t12-20020a05621421ac00b0042c2844aa93mr20363649qvc.130.1645553706796; Tue, 22
Feb 2022 10:15:06 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 22 Feb 2022 10:15:06 -0800 (PST)
In-Reply-To: <qA9RJ.26451$kuda.26153@fx12.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:f5ae:5e9d:c8ee:6c75;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:f5ae:5e9d:c8ee:6c75
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv3711$k46$1@dont-email.me> <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
<qA9RJ.26451$kuda.26153@fx12.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a5735cad-e01f-4305-b3ec-5aa16983b0dbn@googlegroups.com>
Subject: Re: Embedded numbers sorting function (begging post)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Tue, 22 Feb 2022 18:15:07 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 23
 by: Malcolm McLean - Tue, 22 Feb 2022 18:15 UTC

On Tuesday, 22 February 2022 at 18:04:34 UTC, Scott Lurndal wrote:
> Malcolm McLean <malcolm.ar...@gmail.com> writes:
> >On Tuesday, 22 February 2022 at 17:38:03 UTC, Bart wrote:
> >> On 22/02/2022 15:27, Malcolm McLean wrote:
> >> > Anyone got a string comparison function handy which compares strings intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
> >> There are all sorts of problems with this. What is it you're really
> >> trying to do; what does the data look like?
> >>
> >> Simplest might be to just extract the first numeric field and test that
> >> as a number, but this needs to be a decision made on all strings being
> >> compared, rather than case by case.
> >>
> >> Or do you have a specification for such a function?
> >>
> >I'm writing a UI, with graphic "profiles". The user draws a "profile", then grabs it, and gives it a name. The default names go "Profile 1", "Profile 2" and so on.
> >I don't know how many profiles the user will create. Obviously not millions, but low thousands would be humanly possible. I don't know what sort of names
> >he'll give the profiles, but I opted for things like "Noise1", "Noise2" to describe similar profiles. I sort the names in various list boxes, so user can find
> >the prfile he wants by scrolling through the list box and looking alphabetically.
> Well, you could create your own locale and use the strcoll function.
>
> Or you can do a normal C locale sort in descending order instead of
> ascending order if you really want 2 to collate ahead of 1.

"Profile 2" goes behind "Profile 1", but ahead of "Profile 10".

Re: Embedded numbers sorting function (begging post)

<sv7o12$1a3$2@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20533&group=comp.lang.c#20533

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: fork...@panix.com (John Forkosh)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Thu, 24 Feb 2022 10:52:18 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <sv7o12$1a3$2@reader1.panix.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com> <sv3711$k46$1@dont-email.me> <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
Injection-Date: Thu, 24 Feb 2022 10:52:18 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="1347"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: John Forkosh - Thu, 24 Feb 2022 10:52 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
> Anyone got a string comparison function handy which compares strings
> intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
>
> I'm writing a UI, with graphic "profiles"...
> ...I sort the names in various list boxes,

Why not just use qsort()? I've seen your book...I know you can
write the compare function with your eyes closed (and your hands
tied behind your back).
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )

Re: Embedded numbers sorting function (begging post)

<sv8cbn$sgsl$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20535&group=comp.lang.c#20535

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Thu, 24 Feb 2022 16:39:19 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sv8cbn$sgsl$1@news.xmission.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com> <sv3711$k46$1@dont-email.me> <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com> <sv7o12$1a3$2@reader1.panix.com>
Injection-Date: Thu, 24 Feb 2022 16:39:19 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="934805"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 24 Feb 2022 16:39 UTC

In article <sv7o12$1a3$2@reader1.panix.com>,
John Forkosh <forkosh@panix.com> wrote:
>Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
>> Anyone got a string comparison function handy which compares strings
>> intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
>>
>> I'm writing a UI, with graphic "profiles"...
>> ...I sort the names in various list boxes,
>
>Why not just use qsort()? I've seen your book...I know you can
>write the compare function with your eyes closed (and your hands
>tied behind your back).

Well, I assume the goal is to avoid writing new code, but, yes, if he has
to, OP will probably end up doing it himself - re-inventing yet another
wheel.

I took a look at the "natsort" URL posted a few responses upthread. It
looks pretty cool - looks like the author has thought it through pretty
well. I didn't actually download or test it at all, but the writeup seemed
good. If I were OP, I'd check it out.

--
Indeed, most .NET developers couldn't pass CS101 at a third-rate
community college.
- F. Russell -

Re: Embedded numbers sorting function (begging post)

<40f66158-455c-4475-a64f-2c54dd2d46d2n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20536&group=comp.lang.c#20536

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:adf:fe0f:0:b0:1e2:f9dc:6ed with SMTP id n15-20020adffe0f000000b001e2f9dc06edmr3197930wrr.530.1645725057330;
Thu, 24 Feb 2022 09:50:57 -0800 (PST)
X-Received: by 2002:a05:622a:34d:b0:2dd:1364:2555 with SMTP id
r13-20020a05622a034d00b002dd13642555mr3466669qtw.404.1645725056963; Thu, 24
Feb 2022 09:50:56 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 24 Feb 2022 09:50:56 -0800 (PST)
In-Reply-To: <sv8cbn$sgsl$1@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:5d5f:8273:6158:46e6;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:5d5f:8273:6158:46e6
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv3711$k46$1@dont-email.me> <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
<sv7o12$1a3$2@reader1.panix.com> <sv8cbn$sgsl$1@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <40f66158-455c-4475-a64f-2c54dd2d46d2n@googlegroups.com>
Subject: Re: Embedded numbers sorting function (begging post)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Thu, 24 Feb 2022 17:50:57 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 31
 by: Malcolm McLean - Thu, 24 Feb 2022 17:50 UTC

On Thursday, 24 February 2022 at 16:39:50 UTC, Kenny McCormack wrote:
> In article <sv7o12$1a3$2...@reader1.panix.com>,
> John Forkosh <for...@panix.com> wrote:
> >Malcolm McLean <malcolm.ar...@gmail.com> wrote:
> >> Anyone got a string comparison function handy which compares strings
> >> intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
> >>
> >> I'm writing a UI, with graphic "profiles"...
> >> ...I sort the names in various list boxes,
> >
> >Why not just use qsort()? I've seen your book...I know you can
> >write the compare function with your eyes closed (and your hands
> >tied behind your back).
> Well, I assume the goal is to avoid writing new code, but, yes, if he has
> to, OP will probably end up doing it himself - re-inventing yet another
> wheel.
>
> I took a look at the "natsort" URL posted a few responses upthread. It
> looks pretty cool - looks like the author has thought it through pretty
> well. I didn't actually download or test it at all, but the writeup seemed
> good. If I were OP, I'd check it out.
>
It's also surprisingly tricky. Kaz knocked one up in fifteen minutes. I appreciate
the contribution. However he used strtoul to convert the digits to integers.
That was also my first thought, but since the profile names are user-entered,
a user could break it by entering a long number. That might happen if they
used a bar code or something to identify the profile.
Also, you don't really want 01 and 001 to compare equal, because that could lead
to inconsistent results in the user interface.
The nightmare scenario is when you get a rare inconsistency, so that a b
and b a don't return opposite-sign results. That causes C++ std::sort to throw,
bringing the program down.

Re: Embedded numbers sorting function (begging post)

<20220224111622.185@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20539&group=comp.lang.c#20539

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Thu, 24 Feb 2022 19:22:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <20220224111622.185@kylheku.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv3711$k46$1@dont-email.me>
<643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
<sv7o12$1a3$2@reader1.panix.com> <sv8cbn$sgsl$1@news.xmission.com>
<40f66158-455c-4475-a64f-2c54dd2d46d2n@googlegroups.com>
Injection-Date: Thu, 24 Feb 2022 19:22:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="59ee13df4f09a48c9faa15bd6f52201c";
logging-data="19092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//SHbso+tb9BSKeZTC7+dSUGRFofe7sk0="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:/NZ1c4/6AWNk/SBsCDHMjkrD4EI=
 by: Kaz Kylheku - Thu, 24 Feb 2022 19:22 UTC

On 2022-02-24, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
> It's also surprisingly tricky. Kaz knocked one up in fifteen minutes. I appreciate
> the contribution. However he used strtoul to convert the digits to integers.
> That was also my first thought, but since the profile names are user-entered,
> a user could break it by entering a long number.

Right; I didn't put in the error checking for that, but I thought about
the cases that occur. Strtoul won't have undefined behavior on overflow,
but it will put out ULONG_MAX and set errno. The only effect of that is
that all these overflowing ULONG_MAX values will compare higher than
non-overflowing values, and equal to each other.

To test for that and do something, we have to write a 0 into errno,
then check for ULONG_MAX and errno being nonzero. That case could do
something else, like fall back on string behavior or whatever.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Embedded numbers sorting function (begging post)

<sva1ed$pmh$1@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20548&group=comp.lang.c#20548

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: fork...@panix.com (John Forkosh)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 07:45:17 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <sva1ed$pmh$1@reader1.panix.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com> <sv3711$k46$1@dont-email.me> <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com> <sv7o12$1a3$2@reader1.panix.com> <sv8cbn$sgsl$1@news.xmission.com> <40f66158-455c-4475-a64f-2c54dd2d46d2n@googlegroups.com>
Injection-Date: Fri, 25 Feb 2022 07:45:17 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="26321"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: John Forkosh - Fri, 25 Feb 2022 07:45 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
> Kenny McCormack wrote:
>> John Forkosh wrote:
>> > Malcolm McLean <malcolm.ar...@gmail.com> wrote:
>> >> Anyone got a string comparison function handy which compares strings
>> >> intelligently by embedded numbers, so that foo2 compares earlier
>> >> than foo11 ?
>> >>
>> >> I'm writing a UI, with graphic "profiles"...
>> >> ...I sort the names in various list boxes,
>> >
>> > Why not just use qsort()? I've seen your book...I know you can
>> > write the compare function with your eyes closed (and your hands
>> > tied behind your back).
>> >
>> Well, I assume the goal is to avoid writing new code, but, yes,
>> if he has to, OP will probably end up doing it himself - re-inventing
>> yet another wheel.
>>
>> I took a look at the "natsort" URL posted a few responses upthread. It
>> looks pretty cool - looks like the author has thought it through pretty
>> well. I didn't actually download or test it at all, but the writeup
>> seemed good. If I were OP, I'd check it out.
>>
> It's also surprisingly tricky. Kaz knocked one up in fifteen minutes.
> I appreciate the contribution. However he used strtoul to convert
> the digits to integers. That was also my first thought, but since
> the profile names are user-entered, a user could break it by entering
> a long number. That might happen if they used a bar code or something
> to identify the profile. Also, you don't really want 01 and 001 to
> compare equal, because that could lead to inconsistent results in the
> user interface. The nightmare scenario is when you get a rare
> inconsistency, so that a b and b a don't return opposite-sign results.
> That causes C++ std::sort to throw, bringing the program down.

Sounds to me like your problem isn't finding appropriate existing code,
but coming up with the suitable functional specification for your
purpose. And also sounds like that'll ultimately be pretty arcane,
such that you'll likely just have to write it yourself, anyway.
In your place, I'd just write some stub function(s) implementing
a simple but inadequate compare, and get on with completing a first
cut of the overall project. Then come back and re-visit the compare.
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )

Re: Embedded numbers sorting function (begging post)

<slrnt1k6c4.1rfm.grahn+nntp@frailea.sa.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20580&group=comp.lang.c#20580

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: grahn+n...@snipabacken.se (Jorgen Grahn)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: 26 Feb 2022 12:13:56 GMT
Lines: 36
Message-ID: <slrnt1k6c4.1rfm.grahn+nntp@frailea.sa.invalid>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv3711$k46$1@dont-email.me>
<643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
X-Trace: individual.net S362QNRjlqOJ4260+vlMUwAGP+ZGX0JGtOeajp8UUPYaKumtoB
Cancel-Lock: sha1:+2Y87k7hPxGS8pApuw8yxsDrEyo=
User-Agent: slrn/1.0.3 (OpenBSD)
 by: Jorgen Grahn - Sat, 26 Feb 2022 12:13 UTC

On Tue, 2022-02-22, Malcolm McLean wrote:
> On Tuesday, 22 February 2022 at 17:38:03 UTC, Bart wrote:
>> On 22/02/2022 15:27, Malcolm McLean wrote:
>> > Anyone got a string comparison function handy which compares strings intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
>> There are all sorts of problems with this. What is it you're really
>> trying to do; what does the data look like?
>>
>> Simplest might be to just extract the first numeric field and test that
>> as a number, but this needs to be a decision made on all strings being
>> compared, rather than case by case.
>>
>> Or do you have a specification for such a function?
>>
> I'm writing a UI, with graphic "profiles". The user draws a
> "profile", then grabs it, and gives it a name. The default names go
> "Profile 1", "Profile 2" and so on. I don't know how many profiles
> the user will create. Obviously not millions, but low thousands
> would be humanly possible. I don't know what sort of names he'll
> give the profiles, but I opted for things like "Noise1", "Noise2" to
> describe similar profiles. I sort the names in various list boxes,
> so user can find the prfile he wants by scrolling through the list
> box and looking alphabetically.

I'd leave that up to the user, which is what they are already used to
doing when they name files and so on. You can help the user by
suggesting the name "Profile 01" instead of "Profile 1".

I distrust fancy sorting modes, because I have to remember and
understand the specific rules when I'm looking for something in a
sorted list.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Re: Embedded numbers sorting function (begging post)

<0b9e52a7-4d2a-4977-b695-948ea2c7c6b7n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20581&group=comp.lang.c#20581

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:70e:b0:605:b871:6af4 with SMTP id 14-20020a05620a070e00b00605b8716af4mr7148414qkc.747.1645879104374;
Sat, 26 Feb 2022 04:38:24 -0800 (PST)
X-Received: by 2002:a05:620a:22f3:b0:62c:ed1c:d3d3 with SMTP id
p19-20020a05620a22f300b0062ced1cd3d3mr7042034qki.450.1645879104077; Sat, 26
Feb 2022 04:38:24 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!2.us.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 26 Feb 2022 04:38:23 -0800 (PST)
In-Reply-To: <slrnt1k6c4.1rfm.grahn+nntp@frailea.sa.invalid>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:88ce:3664:3e62:8f87;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:88ce:3664:3e62:8f87
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv3711$k46$1@dont-email.me> <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
<slrnt1k6c4.1rfm.grahn+nntp@frailea.sa.invalid>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0b9e52a7-4d2a-4977-b695-948ea2c7c6b7n@googlegroups.com>
Subject: Re: Embedded numbers sorting function (begging post)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Sat, 26 Feb 2022 12:38:24 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 43
 by: Malcolm McLean - Sat, 26 Feb 2022 12:38 UTC

On Saturday, 26 February 2022 at 12:14:34 UTC, Jorgen Grahn wrote:
> On Tue, 2022-02-22, Malcolm McLean wrote:
> > On Tuesday, 22 February 2022 at 17:38:03 UTC, Bart wrote:
> >> On 22/02/2022 15:27, Malcolm McLean wrote:
> >> > Anyone got a string comparison function handy which compares strings intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
> >> There are all sorts of problems with this. What is it you're really
> >> trying to do; what does the data look like?
> >>
> >> Simplest might be to just extract the first numeric field and test that
> >> as a number, but this needs to be a decision made on all strings being
> >> compared, rather than case by case.
> >>
> >> Or do you have a specification for such a function?
> >>
> > I'm writing a UI, with graphic "profiles". The user draws a
> > "profile", then grabs it, and gives it a name. The default names go
> > "Profile 1", "Profile 2" and so on. I don't know how many profiles
> > the user will create. Obviously not millions, but low thousands
> > would be humanly possible. I don't know what sort of names he'll
> > give the profiles, but I opted for things like "Noise1", "Noise2" to
> > describe similar profiles. I sort the names in various list boxes,
> > so user can find the prfile he wants by scrolling through the list
> > box and looking alphabetically.
>
> I'd leave that up to the user, which is what they are already used to
> doing when they name files and so on. You can help the user by
> suggesting the name "Profile 01" instead of "Profile 1".
>
> I distrust fancy sorting modes, because I have to remember and
> understand the specific rules when I'm looking for something in a
> sorted list.
>
The artist drew some "noise" profiles for me. He didn't give me any
names, so I put them into the system as "Noise 1", "Noise 2" and so on,
up to "Noise 13". Of course it sorted badly. I don't really want to ship
with pre-loaded profiles sorted in a funny way, though the names might
well change.
"Noise 01" isn't a good answer. It's not conventional to show leading zeroes.
And the user might well draw half a dozen profiles, which he labels as
"Scrollwork 1", "Scrollwork 2" and so on. Then a few months later, he
adds another half dozen, taking him up to "Scrollwork 12". Now "Scrollwork 1"
has to be changed to "Scrollwork 01". Whilst the system allows him to do
that, what it won't do is allow him to keep all the other copies of the profile
in all the other machines in his workgroup in synch.

Re: Embedded numbers sorting function (begging post)

<slrnt1kq9g.1rfm.grahn+nntp@frailea.sa.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20587&group=comp.lang.c#20587

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: grahn+n...@snipabacken.se (Jorgen Grahn)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: 26 Feb 2022 17:53:52 GMT
Lines: 55
Message-ID: <slrnt1kq9g.1rfm.grahn+nntp@frailea.sa.invalid>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv3711$k46$1@dont-email.me>
<643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
<slrnt1k6c4.1rfm.grahn+nntp@frailea.sa.invalid>
<0b9e52a7-4d2a-4977-b695-948ea2c7c6b7n@googlegroups.com>
X-Trace: individual.net b3hZUg2zdDwDQy3DdATK6AUXWBfY0Zgbgg4epq+OKaYR+KLZoc
Cancel-Lock: sha1:6AN0l7pYhm4VchRB7yxyrZYPdlI=
User-Agent: slrn/1.0.3 (OpenBSD)
 by: Jorgen Grahn - Sat, 26 Feb 2022 17:53 UTC

On Sat, 2022-02-26, Malcolm McLean wrote:
> On Saturday, 26 February 2022 at 12:14:34 UTC, Jorgen Grahn wrote:
>> On Tue, 2022-02-22, Malcolm McLean wrote:
>> > On Tuesday, 22 February 2022 at 17:38:03 UTC, Bart wrote:
>> >> On 22/02/2022 15:27, Malcolm McLean wrote:
>> >> > Anyone got a string comparison function handy which compares strings intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
>> >> There are all sorts of problems with this. What is it you're really
>> >> trying to do; what does the data look like?
>> >>
>> >> Simplest might be to just extract the first numeric field and test that
>> >> as a number, but this needs to be a decision made on all strings being
>> >> compared, rather than case by case.
>> >>
>> >> Or do you have a specification for such a function?
>> >>
>> > I'm writing a UI, with graphic "profiles". The user draws a
>> > "profile", then grabs it, and gives it a name. The default names go
>> > "Profile 1", "Profile 2" and so on. I don't know how many profiles
>> > the user will create. Obviously not millions, but low thousands
>> > would be humanly possible. I don't know what sort of names he'll
>> > give the profiles, but I opted for things like "Noise1", "Noise2" to
>> > describe similar profiles. I sort the names in various list boxes,
>> > so user can find the prfile he wants by scrolling through the list
>> > box and looking alphabetically.
>>
>> I'd leave that up to the user, which is what they are already used to
>> doing when they name files and so on. You can help the user by
>> suggesting the name "Profile 01" instead of "Profile 1".
>>
>> I distrust fancy sorting modes, because I have to remember and
>> understand the specific rules when I'm looking for something in a
>> sorted list.
>>
> The artist drew some "noise" profiles for me. He didn't give me any
> names, so I put them into the system as "Noise 1", "Noise 2" and so on,
> up to "Noise 13". Of course it sorted badly. I don't really want to ship
> with pre-loaded profiles sorted in a funny way, though the names might
> well change.
> "Noise 01" isn't a good answer. It's not conventional to show leading zeroes.

Yes, it is, in many areas. The only reason we write dates as e.g.
2022-02-26 is so they sort well. And at my workplace, when we're
e.g. numbering test cases or sets of related files, whoever comes up
with the names invariably adds leading zeros.

It's not something I necessarily like all of the time, because I think
machines should adapt to people and not the other way around ... But
if the alternative is to see entry #20 listed between #2 and #3, it's
what I'd do.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Re: Embedded numbers sorting function (begging post)

<35225666-3e23-4c28-aa07-bf4655ac837fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20588&group=comp.lang.c#20588

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:f08:b0:433:6cf:9f7c with SMTP id gw8-20020a0562140f0800b0043306cf9f7cmr1245757qvb.71.1645900891831;
Sat, 26 Feb 2022 10:41:31 -0800 (PST)
X-Received: by 2002:ac8:7e91:0:b0:2de:29d4:123d with SMTP id
w17-20020ac87e91000000b002de29d4123dmr11394001qtj.322.1645900891651; Sat, 26
Feb 2022 10:41:31 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 26 Feb 2022 10:41:31 -0800 (PST)
In-Reply-To: <slrnt1kq9g.1rfm.grahn+nntp@frailea.sa.invalid>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:88ce:3664:3e62:8f87;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:88ce:3664:3e62:8f87
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv3711$k46$1@dont-email.me> <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
<slrnt1k6c4.1rfm.grahn+nntp@frailea.sa.invalid> <0b9e52a7-4d2a-4977-b695-948ea2c7c6b7n@googlegroups.com>
<slrnt1kq9g.1rfm.grahn+nntp@frailea.sa.invalid>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <35225666-3e23-4c28-aa07-bf4655ac837fn@googlegroups.com>
Subject: Re: Embedded numbers sorting function (begging post)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Sat, 26 Feb 2022 18:41:31 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 55
 by: Malcolm McLean - Sat, 26 Feb 2022 18:41 UTC

On Saturday, 26 February 2022 at 17:54:23 UTC, Jorgen Grahn wrote:
> On Sat, 2022-02-26, Malcolm McLean wrote:
> > On Saturday, 26 February 2022 at 12:14:34 UTC, Jorgen Grahn wrote:
> >> On Tue, 2022-02-22, Malcolm McLean wrote:
> >> > On Tuesday, 22 February 2022 at 17:38:03 UTC, Bart wrote:
> >> >> On 22/02/2022 15:27, Malcolm McLean wrote:
> >> >> > Anyone got a string comparison function handy which compares strings intelligently by embedded numbers, so that foo2 compares earlier than foo11 ?
> >> >> There are all sorts of problems with this. What is it you're really
> >> >> trying to do; what does the data look like?
> >> >>
> >> >> Simplest might be to just extract the first numeric field and test that
> >> >> as a number, but this needs to be a decision made on all strings being
> >> >> compared, rather than case by case.
> >> >>
> >> >> Or do you have a specification for such a function?
> >> >>
> >> > I'm writing a UI, with graphic "profiles". The user draws a
> >> > "profile", then grabs it, and gives it a name. The default names go
> >> > "Profile 1", "Profile 2" and so on. I don't know how many profiles
> >> > the user will create. Obviously not millions, but low thousands
> >> > would be humanly possible. I don't know what sort of names he'll
> >> > give the profiles, but I opted for things like "Noise1", "Noise2" to
> >> > describe similar profiles. I sort the names in various list boxes,
> >> > so user can find the prfile he wants by scrolling through the list
> >> > box and looking alphabetically.
> >>
> >> I'd leave that up to the user, which is what they are already used to
> >> doing when they name files and so on. You can help the user by
> >> suggesting the name "Profile 01" instead of "Profile 1".
> >>
> >> I distrust fancy sorting modes, because I have to remember and
> >> understand the specific rules when I'm looking for something in a
> >> sorted list.
> >>
> > The artist drew some "noise" profiles for me. He didn't give me any
> > names, so I put them into the system as "Noise 1", "Noise 2" and so on,
> > up to "Noise 13". Of course it sorted badly. I don't really want to ship
> > with pre-loaded profiles sorted in a funny way, though the names might
> > well change.
> > "Noise 01" isn't a good answer. It's not conventional to show leading zeroes.
> Yes, it is, in many areas. The only reason we write dates as e.g.
> 2022-02-26 is so they sort well. And at my workplace, when we're
> e.g. numbering test cases or sets of related files, whoever comes up
> with the names invariably adds leading zeros.
>
> It's not something I necessarily like all of the time, because I think
> machines should adapt to people and not the other way around ... But
> if the alternative is to see entry #20 listed between #2 and #3, it's
> what I'd do.
>
If you rely on the operating system to sort filenames for you, then of course
there's nothing you can do. You have to accept their sorting function and
adapt the filenames to it. But that's not the case here. Whilst the profiles
are in fact stored as files with a filename based on the profile name, they
are stored in a hidden directory. They are then displayed in scrolling list boxes
in the user interface.

Re: Embedded numbers sorting function (begging post)

<sve064$1se3$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20591&group=comp.lang.c#20591

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Sat, 26 Feb 2022 20:48:20 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sve064$1se3$1@gioia.aioe.org>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv3711$k46$1@dont-email.me>
<643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
<slrnt1k6c4.1rfm.grahn+nntp@frailea.sa.invalid>
<0b9e52a7-4d2a-4977-b695-948ea2c7c6b7n@googlegroups.com>
<slrnt1kq9g.1rfm.grahn+nntp@frailea.sa.invalid>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="61891"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Manfred - Sat, 26 Feb 2022 19:48 UTC

On 2/26/2022 6:53 PM, Jorgen Grahn wrote:
> On Sat, 2022-02-26, Malcolm McLean wrote:
[...]
>> The artist drew some "noise" profiles for me. He didn't give me any
>> names, so I put them into the system as "Noise 1", "Noise 2" and so on,
>> up to "Noise 13". Of course it sorted badly. I don't really want to ship
>> with pre-loaded profiles sorted in a funny way, though the names might
>> well change.
>> "Noise 01" isn't a good answer. It's not conventional to show leading zeroes.
>
> Yes, it is, in many areas. The only reason we write dates as e.g.
> 2022-02-26 is so they sort well. And at my workplace, when we're
> e.g. numbering test cases or sets of related files, whoever comes up
> with the names invariably adds leading zeros.
>
> It's not something I necessarily like all of the time, because I think
> machines should adapt to people and not the other way around ... But
> if the alternative is to see entry #20 listed between #2 and #3, it's
> what I'd do.

That depends entirely on context, and what people in such context are
used to.
In the IT world your example (2022-02-26, or numbering like 001, 002,
....) fits a very common practice, for obvious reasons.

In the Real World™ things may be very different...

That's the challenge for the OP: consistent results with "natural"
counters and identifiers.

>
> /Jorgen
>

Re: Embedded numbers sorting function (begging post)

<svf7kl$cop$1@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20596&group=comp.lang.c#20596

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: fork...@panix.com (John Forkosh)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Sun, 27 Feb 2022 07:01:41 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <svf7kl$cop$1@reader1.panix.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com> <sv3711$k46$1@dont-email.me> <643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com> <slrnt1k6c4.1rfm.grahn+nntp@frailea.sa.invalid> <0b9e52a7-4d2a-4977-b695-948ea2c7c6b7n@googlegroups.com> <slrnt1kq9g.1rfm.grahn+nntp@frailea.sa.invalid> <35225666-3e23-4c28-aa07-bf4655ac837fn@googlegroups.com>
Injection-Date: Sun, 27 Feb 2022 07:01:41 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="13081"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: John Forkosh - Sun, 27 Feb 2022 07:01 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
> Jorgen Grahn wrote:
>> Malcolm McLean wrote:
>> > Jorgen Grahn wrote:
>> >> Malcolm McLean wrote:
>> >> > Anyone got a string comparison function handy which
>> >> > compares strings intelligently by embedded numbers,
>> >> > so that foo2 compares earlier than foo11 ?
>> >> >
>> >> > I'm writing a UI, with graphic "profiles". The user draws a
>> >> > "profile", then grabs it, and gives it a name. The default names go
>> >> > "Profile 1", "Profile 2" and so on. I don't know how many profiles
>> >> > the user will create. Obviously not millions, but low thousands
>> >> > would be humanly possible. I don't know what sort of names he'll
>> >> > give the profiles, but I opted for things like "Noise1", "Noise2" to
>> >> > describe similar profiles. I sort the names in various list boxes,
>> >> > so user can find the prfile he wants by scrolling through the list
>> >> > box and looking alphabetically.
>> >>
>> >> I'd leave that up to the user, which is what they are already used to
>> >> doing when they name files and so on. You can help the user by
>> >> suggesting the name "Profile 01" instead of "Profile 1".
>> >> I distrust fancy sorting modes, because I have to remember and
>> >> understand the specific rules when I'm looking for something in a
>> >> sorted list.
>> >>
>> > The artist drew some "noise" profiles for me. He didn't give me any
>> > names, so I put them into the system as "Noise 1", "Noise 2" and so on,
>> > up to "Noise 13". Of course it sorted badly. I don't really want to ship
>> > with pre-loaded profiles sorted in a funny way, though the names might
>> > well change. "Noise 01" isn't a good answer. It's not conventional
>> > to show leading zeroes.
>> >
>> Yes, it is, in many areas. The only reason we write dates as e.g.
>> 2022-02-26 is so they sort well. And at my workplace, when we're
>> e.g. numbering test cases or sets of related files, whoever comes up
>> with the names invariably adds leading zeros.
>> It's not something I necessarily like all of the time, because I think
>> machines should adapt to people and not the other way around ... But
>> if the alternative is to see entry #20 listed between #2 and #3, it's
>> what I'd do.
>>
> If you rely on the operating system to sort filenames for you,
> then of course there's nothing you can do. You have to accept
> their sorting function and adapt the filenames to it.
> But that's not the case here. Whilst the profiles are in fact
> stored as files with a filename based on the profile name, they
> are stored in a hidden directory. They are then displayed in
> scrolling list boxes in the user interface.

Maybe you might try an approach similar to what firefox does
when you point it to a directory on your local machine, e.g.,
Index of file:///hdd/sdb5/global/reference/toc/
Up to higher level directory
Name Size Last Modified
&.pdf 35 KB 2/6/21 21:50:18 EST
(22) (New Mathema 3220 KB 2/19/19 04:16:58 EST
(A Series of Moder 2460 KB 3/15/20 04:19:06 EDT
(Abel Symposia 4) 2598 KB 3/17/19 00:27:12 EDT
etc
It default displays files sorted by "Name". But you can
click on any of those three "Name" "Size" "Last Modified"
headings, and it re-sorts the list sorted on that field.
And if you click the same heading again, it reverse-sorts
that field. Gives the user lots of personal preference
choices, which seems to be what you're trying to accomplish.
So you might modify firefox's approach in two ways that I can
immediately think of (and probably more I haven't thought of).
1: choice of fields and headings displayed, and 2: especially
for the Name field, more than just two ways of sorting that
the user can click-click-click... through until he finds
a sort order that he likes.
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )

Re: Embedded numbers sorting function (begging post)

<20220227102226.691@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20597&group=comp.lang.c#20597

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Sun, 27 Feb 2022 18:27:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <20220227102226.691@kylheku.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv3711$k46$1@dont-email.me>
<643ebed9-0466-4840-89e6-c44aebff501an@googlegroups.com>
<slrnt1k6c4.1rfm.grahn+nntp@frailea.sa.invalid>
<0b9e52a7-4d2a-4977-b695-948ea2c7c6b7n@googlegroups.com>
<slrnt1kq9g.1rfm.grahn+nntp@frailea.sa.invalid>
<35225666-3e23-4c28-aa07-bf4655ac837fn@googlegroups.com>
<svf7kl$cop$1@reader1.panix.com>
Injection-Date: Sun, 27 Feb 2022 18:27:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="def0d4f6921e96474b79175c7028038d";
logging-data="31156"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pprj+ECMeBH//iUmclSFrq+gsGjW4nKM="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:nTZ2kOMwEP9wAD2RwQ92bgoVAAY=
 by: Kaz Kylheku - Sun, 27 Feb 2022 18:27 UTC

On 2022-02-27, John Forkosh <forkosh@panix.com> wrote:
> [Firefox] default displays files sorted by "Name". But you can
> click on any of those three "Name" "Size" "Last Modified"
> headings, and it re-sorts the list sorted on that field.
> And if you click the same heading again, it reverse-sorts
> that field.

I find it curious that you're narrating this from a Firefox perspective;
these behaviors in table handling are a wide-spread pattern in the
consumer UI landscape of what, the past 25 years at least?

If you make it an option that the user can select to have the name
column sorted undersome embedded number semantics (e.g. check box in a
context menu that pops up if you right-click on the column), under the
hood you will still need that comparison function to support it.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor