Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and may be fixed. Will keep monitoring.


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

SubjectAuthor
* Re: Embedded numbers sorting function (begging post)Bonita Montero
`* Re: Embedded numbers sorting function (begging post)Kaz Kylheku
 `* Re: Embedded numbers sorting function (begging post)Bonita Montero
  `* Re: Embedded numbers sorting function (begging post)Kaz Kylheku
   +* Re: Embedded numbers sorting function (begging post)Bonita Montero
   |+* Re: Embedded numbers sorting function (begging post)Kenny McCormack
   ||+* Re: Embedded numbers sorting function (begging post)Bonita Montero
   |||+- Re: Embedded numbers sorting function (begging post)Kenny McCormack
   |||`* Re: Embedded numbers sorting function (begging post)Kaz Kylheku
   ||| `- Re: Embedded numbers sorting function (begging post)Bonita Montero
   ||`- 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)Bonita Montero
   ||`* Re: Embedded numbers sorting function (begging post)Keith Thompson
   || `- Re: Embedded numbers sorting function (begging post)Bonita Montero
   |+* Re: Embedded numbers sorting function (begging post)Ben Bacarisse
   ||+* Re: Embedded numbers sorting function (begging post)Bonita Montero
   |||`* Re: Embedded numbers sorting function (begging post)Ben Bacarisse
   ||| +* Re: Embedded numbers sorting function (begging post)Bonita Montero
   ||| |`- Re: Embedded numbers sorting function (begging post)Ben Bacarisse
   ||| `- Re: Embedded numbers sorting function (begging post)Lew Pitcher
   ||`* Re: Embedded numbers sorting function (begging post)Bonita Montero
   || `* 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)Richard Damon
   ||   +- Re: Embedded numbers sorting function (begging post)Keith Thompson
   ||   `- Re: Embedded numbers sorting function (begging post)James Kuyper
   |+* Re: Embedded numbers sorting function (begging post)Kaz Kylheku
   ||`* Re: Embedded numbers sorting function (begging post)Bonita Montero
   || `* Re: Embedded numbers sorting function (begging post)Kenny McCormack
   ||  `- Re: Embedded numbers sorting function (begging post)Scott Lurndal
   |`* Re: Embedded numbers sorting function (begging post)James Kuyper
   | `* Re: Embedded numbers sorting function (begging post)Bonita Montero
   |  `* Re: Embedded numbers sorting function (begging post)Scott Lurndal
   |   +- Re: Embedded numbers sorting function (begging post)Bonita Montero
   |   `- Re: Embedded numbers sorting function (begging post)Bonita Montero
   `* Re: Embedded numbers sorting function (begging post)Bonita Montero
    `* Re: Embedded numbers sorting function (begging post)Bonita Montero
     `- Re: Embedded numbers sorting function (begging post)Bonita Montero

Pages:12
Re: Embedded numbers sorting function (begging post)

<sv8tlj$i1l$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Thu, 24 Feb 2022 22:34:43 +0100
Organization: A noiseless patient Spider
Lines: 107
Message-ID: <sv8tlj$i1l$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: Thu, 24 Feb 2022 21:34:43 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="840ba5077ace3a7b09b223cf6ad144f8";
logging-data="18485"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1wopVhR4C2+F+E//PzQL5qK4TWEkfYeg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:8ouGVOj+e0tn6Dirywp/kFysSx0=
In-Reply-To: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Thu, 24 Feb 2022 21:34 UTC

Look at this solution in C++:

#include <string_view>
#include <compare>
#include <type_traits>
#include <cctype>
#include <stdexcept>
#include <cstdint>
#include <cassert>

template<typename CharType, typename Traits>
requires
std::is_same_v<std::make_unsigned_t<CharType>, unsigned char> ||
std::is_same_v<CharType, wchar_t>
&&
requires( CharType const *str, size_t n ) { { Traits::compare( str,
str, n ) } -> std::same_as<int>; }
int numberedStrCmp( std::basic_string_view<CharType, Traits> const
&left, std::basic_string_view<CharType, Traits> const &right )
{ using str_cit = typename std::basic_string_view<CharType,
Traits>::const_iterator;
auto parseDigits = []( str_cit &it, str_cit end ) -> uint64_t
{
assert(!isdigit( *it ));
uint64_t value = 0;
do
{
if( value * 10 / 10 != value )
throw std::out_of_range( "numberedStrCmp() - number too big" );
value *= 10;
unsigned digit = *it - '0';
if( value + digit < value )
throw std::out_of_range( "numberedStrCmp() - number too big" );
value += digit;
} while( ++it != end && isdigit( *it ) );
return value;
};
auto skipDigits = []( str_cit &it )
{
while( isdigit( *++it ) );
};
str_cit itLeft = left.cbegin(), itRight = right.cbegin();
auto compareCurChar = [&]() -> int
{
bool
leftDigit = isdigit( *itLeft ),
rightDigit = isdigit( *itRight );
if( leftDigit && rightDigit )
{
uint64_t
leftNumber = parseDigits( itLeft, left.cend() ),
rightNumber = parseDigits( itRight, right.cend() );
return leftNumber == rightNumber ? 0 : leftNumber < rightNumber ? -1
: +1;
}
else if( leftDigit || rightDigit )
{
auto cmpDigitChar = []( CharType chr ) -> int
{
CharType cmpDigit = '0';
return Traits::compare( &cmpDigit, &chr, 1 );
};
if( leftDigit )
{
skipDigits( itLeft );
return cmpDigitChar( *itRight++ );
}
else
{
skipDigits( itRight );
return -cmpDigitChar( *itLeft++ );
}
}
return Traits::compare( &*itLeft++, &*itRight++, 1 );
};
for( ; ; )
{
auto zeroCmp = []( CharType chr )
{
CharType zero = '\0';
return Traits::compare( &zero, &chr, 1 );
};
if( itLeft == left.cend() )
return itRight != right.cend() ? zeroCmp( *itRight ) : 0;
if( itRight == right.cend() )
return -zeroCmp( *itLeft );
int cmp = compareCurChar();
if( cmp != 0 )
return cmp;
}
}

using namespace std;

#if !defined(NDEBUG)
template
int numberedStrCmp( basic_string_view<char, char_traits<char>> const
&left, basic_string_view<char, char_traits<char>> const &right );
#endif

Two advantages of this solution:
* It works with normal chars as well as wide-characters
* It honors customized collation-orders implemented in the Traits type

The only disadvantage is that it currently doesn't support multibyte
-characters.

Re: Embedded numbers sorting function (begging post)

<20220224141441.215@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!news.freedyn.de!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 22:16:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <20220224141441.215@kylheku.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me>
Injection-Date: Thu, 24 Feb 2022 22:16:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="59ee13df4f09a48c9faa15bd6f52201c";
logging-data="2479"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jo9UHxfeS2NvWoOpljeZsM79pR8ziAC8="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:7bWwYDxiNMu4NjGLTbwt3WX6yfg=
 by: Kaz Kylheku - Thu, 24 Feb 2022 22:16 UTC

On 2022-02-24, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Look at this solution in C++:

Dog's breakfast.

> auto parseDigits = []( str_cit &it, str_cit end ) -> uint64_t
> {
> assert(!isdigit( *it ));
> uint64_t value = 0;
> do
> {
> if( value * 10 / 10 != value )
> throw std::out_of_range( "numberedStrCmp() - number too big" );
> value *= 10;
> unsigned digit = *it - '0';
> if( value + digit < value )
> throw std::out_of_range( "numberedStrCmp() - number too big" );
> value += digit;
> } while( ++it != end && isdigit( *it ) );
> return value;

All those C++ libraries, and you have to write your own loop to
scan digits and produce an unsigned integer???

You are incompetent beyond belief.

Re: Embedded numbers sorting function (begging post)

<sv90fi$5gl$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Thu, 24 Feb 2022 23:22:42 +0100
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <sv90fi$5gl$1@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 24 Feb 2022 22:22:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="840ba5077ace3a7b09b223cf6ad144f8";
logging-data="5653"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Dny7LV12qpEDfHYEIzaFog5C8zvkp+ew="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:6M5zJqawjmtezZEkEIWvV8HZ+rw=
In-Reply-To: <20220224141441.215@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Thu, 24 Feb 2022 22:22 UTC

Am 24.02.2022 um 23:16 schrieb Kaz Kylheku:
> On 2022-02-24, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Look at this solution in C++:
>
> Dog's breakfast.
>
>> auto parseDigits = []( str_cit &it, str_cit end ) -> uint64_t
>> {
>> assert(!isdigit( *it ));
>> uint64_t value = 0;
>> do
>> {
>> if( value * 10 / 10 != value )
>> throw std::out_of_range( "numberedStrCmp() - number too big" );
>> value *= 10;
>> unsigned digit = *it - '0';
>> if( value + digit < value )
>> throw std::out_of_range( "numberedStrCmp() - number too big" );
>> value += digit;
>> } while( ++it != end && isdigit( *it ) );
>> return value;
>
> All those C++ libraries, and you have to write your own loop to
> scan digits and produce an unsigned integer???

Yes, because there is no universal function that fits for wide
characters also. from_chars has a nice api-design but it is is
char only.

Re: Embedded numbers sorting function (begging post)

<20220224142724.547@kylheku.com>

  copy mid

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

  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 22:46:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <20220224142724.547@kylheku.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me>
Injection-Date: Thu, 24 Feb 2022 22:46:40 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="59ee13df4f09a48c9faa15bd6f52201c";
logging-data="7808"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qWSfDtDXpToS1IqGvXb7LaHRDFVSAelA="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:m6y12ohZmRok8eYVqldVIkl5VVg=
 by: Kaz Kylheku - Thu, 24 Feb 2022 22:46 UTC

On 2022-02-24, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 24.02.2022 um 23:16 schrieb Kaz Kylheku:
>> On 2022-02-24, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>> Look at this solution in C++:
>>
>> Dog's breakfast.
>>
>>> auto parseDigits = []( str_cit &it, str_cit end ) -> uint64_t
>>> {
>>> assert(!isdigit( *it ));

You don't want to pass wide characters or other junk into isdigit!

It has undefined behavior for values other than EOF and 0 to
UCHAR_MAX!

Even char is not safe, because it can be signed and exhibit negative
values that are not EOF.

Since the code is supposed to be generic between char and wchar_t,
what you can do is use iswdigit function for both cases. But that is tricky.

You have to be careful how you convert a char to a wchar. If a char value is,
say, -128, you don't want to just be casting that to wchar_t because you will
get some huge value. Rather, you want something like
(wchar_t) (unsigned char) c.

Now iswdigit takes a wint_t, not a wchar_t. wint_t is capable of holding the value
WEOF. (WEOF is not required to have the same value as EOF, and need not be
negative.)

The wide character classification functions don't have the same pitfall
as the classic ones; there is no statement saying that the functions are
only required to work for some restricted subrange of their wint_t argument,

>>> uint64_t value = 0;
>>> do
>>> {
>>> if( value * 10 / 10 != value )
>>> throw std::out_of_range( "numberedStrCmp() - number too big" );

Someone just wanted a nicer sort for displaying file names; now
you're killing the program with a surprise exception when someone has
a file name with too many consecutive digits somewhere in it.

>> All those C++ libraries, and you have to write your own loop to
>> scan digits and produce an unsigned integer???
>
> Yes, because there is no universal function that fits for wide
> characters also.

wcstoul, wcstoull, since ISO C99, declared in <wchar.h>.

For uintmax_t, there is wcstoumax, in <inttypes.h>, also requiring
<stddef.h>.

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

Re: Embedded numbers sorting function (begging post)

<sv9qfh$kec$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 06:46:25 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <sv9qfh$kec$1@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Feb 2022 05:46:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="20940"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GZTpS/eJrTTvvkdUkghens75wptceT/8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:eAqJ0Znt8u3BcQrl1vTQYyytOXQ=
In-Reply-To: <20220224142724.547@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 05:46 UTC

Am 24.02.2022 um 23:46 schrieb Kaz Kylheku:

> You don't want to pass wide characters or other junk into isdigit!

isdigit takes an int.

> Even char is not safe, because it can be signed and exhibit negative
> values that are not EOF.

As the boundary between signed and and unsigned ints doesn't fall
within >= '0' and <= '9' it isn't a problem that isdgit takes an int.

> You have to be careful how you convert a char to a wchar. If a char value is,
> say, -128, you don't want to just be casting that to wchar_t because you will
> get some huge value. Rather, you want something like
> (wchar_t) (unsigned char) c.

You're stupid.

>>>> uint64_t value = 0;
>>>> do
>>>> {
>>>> if( value * 10 / 10 != value )
>>>> throw std::out_of_range( "numberedStrCmp() - number too big" );
>
> Someone just wanted a nicer sort for displaying file names; now
> you're killing the program with a surprise exception when someone has
> a file name with too many consecutive digits somewhere in it.

Then you need additional handling inside an exception-handler.

Re: Embedded numbers sorting function (begging post)

<sv9un6$9iq$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 07:58:47 +0100
Organization: A noiseless patient Spider
Lines: 106
Message-ID: <sv9un6$9iq$1@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Feb 2022 06:58:46 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="9818"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lsCX6mzRXz+nDs08hSgQ6RbsBu0KzYhg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:vVLE11XRv2MmHNhJW4qO3yxpgT0=
In-Reply-To: <20220224142724.547@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 06:58 UTC

> wcstoul, wcstoull, since ISO C99, declared in <wchar.h>.

I'd have to use a if constexpr then and wcstoul and wcstoull don't
honor any collation orders implemented in Traits.

Here's a better version that allows arbitraty number lengths:

#include <string_view>
#include <compare>
#include <type_traits>
#include <cctype>
#include <stdexcept>
#include <cstdint>
#include <cassert>

template<typename CharType, typename Traits>
requires
std::is_same_v<std::make_unsigned_t<CharType>, unsigned char> ||
std::is_same_v<CharType, wchar_t>
&&
requires( CharType const *str, size_t n ) { { Traits::compare( str,
str, n ) } -> std::same_as<int>; }
int numberedStrCmp( std::basic_string_view<CharType, Traits> const
&left, std::basic_string_view<CharType, Traits> const &right )
{ using str_cit = typename std::basic_string_view<CharType,
Traits>::const_iterator;
str_cit itLeft = left.cbegin(), itRight = right.cbegin();
auto digitsCmp = [&]() -> int
{
auto nDigits = []( str_cit &it, str_cit end ) -> ptrdiff_t
{
assert(isdigit( *it ));
str_cit begin = it;
while( ++it != end && isdigit( *it ) );
return it - begin;
};
ptrdiff_t
nLeftDigits = nDigits( itLeft, left.cend() ),
nRightDigits = nDigits( itRight, right.cend() );
if( nLeftDigits != nRightDigits )
return nLeftDigits < nRightDigits ? -1 : 1;
nLeftDigits = -nLeftDigits;
do
if( itLeft[nLeftDigits] != itRight[nLeftDigits] )
return itLeft[nLeftDigits] < itRight[nLeftDigits] ? -1 : 1;
while( ++nLeftDigits );
return 0;
};
auto skipDigits = []( str_cit &it )
{
while( isdigit( *++it ) );
};
auto compareCurChar = [&]() -> int
{
bool
leftDigit = isdigit( *itLeft ),
rightDigit = isdigit( *itRight );
if( leftDigit && rightDigit )
return digitsCmp();
else if( leftDigit || rightDigit )
{
auto cmpDigitChar = []( CharType chr ) -> int
{
CharType cmpDigit = '0';
return Traits::compare( &cmpDigit, &chr, 1 );
};
if( leftDigit )
{
skipDigits( itLeft );
return cmpDigitChar( *itRight++ );
}
else
{
skipDigits( itRight );
return -cmpDigitChar( *itLeft++ );
}
}
return Traits::compare( &*itLeft++, &*itRight++, 1 );
};
for( ; ; )
{
auto zeroCmp = []( CharType chr )
{
CharType zero = '\0';
return Traits::compare( &zero, &chr, 1 );
};
if( itLeft == left.cend() )
return itRight != right.cend() ? zeroCmp( *itRight ) : 0;
if( itRight == right.cend() )
return -zeroCmp( *itLeft );
int cmp = compareCurChar();
if( cmp != 0 )
return cmp;
}
}

using namespace std;

#if !defined(NDEBUG)
template
int numberedStrCmp( basic_string_view<char, char_traits<char>> const
&left, basic_string_view<char, char_traits<char>> const &right );
#endif

Re: Embedded numbers sorting function (begging post)

<sva1e6$tdhd$1@news.xmission.com>

  copy mid

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

  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: Fri, 25 Feb 2022 07:45:10 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sva1e6$tdhd$1@news.xmission.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com> <sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com> <sv9qfh$kec$1@dont-email.me>
Injection-Date: Fri, 25 Feb 2022 07:45:10 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="964141"; 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 - Fri, 25 Feb 2022 07:45 UTC

In article <sv9qfh$kec$1@dont-email.me>,
Bonita Montero <Bonita.Montero@gmail.com> wrote:
....
>You're stupid.

That's rich. Someone posting C++ garbage in a C newsgroup, calling someone
else "stupid". If you keep at it, I may have to start posting my PL/I
solutions on these threads.

That said, gotta give ya credit for spelling "You're" correctly. Most
folks of your general IQ level would have misspelled it.

--
[Donald] Trump didn't have it all handed to him by his parents,
like Hillary Clinton did.

- Some dumb cluck in Ohio; featured in Michael Moore's "Trumpland" -

Re: Embedded numbers sorting function (begging post)

<sva62c$ktu$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 10:04:13 +0100
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <sva62c$ktu$1@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me> <sva1e6$tdhd$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Feb 2022 09:04:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="21438"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+drPaI/fdgxd+QRceEGLBEMMYLBcxOsU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:6OOfjnkcWFQoA4l4Xvl2uuZLq/4=
In-Reply-To: <sva1e6$tdhd$1@news.xmission.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 09:04 UTC

Am 25.02.2022 um 08:45 schrieb Kenny McCormack:
> In article <sv9qfh$kec$1@dont-email.me>,
> Bonita Montero <Bonita.Montero@gmail.com> wrote:
> ...
>> You're stupid.
>
> That's rich. Someone posting C++ garbage in a C newsgroup, calling someone
> else "stupid". If you keep at it, I may have to start posting my PL/I
> solutions on these threads.

C++ isn't garbage but just the more suitable langauage.

Re: Embedded numbers sorting function (begging post)

<sva63f$ktu$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 10:04:48 +0100
Organization: A noiseless patient Spider
Lines: 112
Message-ID: <sva63f$ktu$2@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9un6$9iq$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 25 Feb 2022 09:04:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="21438"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vcPDNGTSxUsJ+GyvZknlFx8QiHX4z4Ic="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:crPu5nuolYPCoRdE0G3lWOKP614=
In-Reply-To: <sv9un6$9iq$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 09:04 UTC

The below solution compares numbers with leading zeroes not correctly.
I'll fix this.

Am 25.02.2022 um 07:58 schrieb Bonita Montero:
>
>> wcstoul, wcstoull, since ISO C99, declared in <wchar.h>.
>
> I'd have to use a if constexpr then and wcstoul and wcstoull don't
> honor any collation orders implemented in Traits.
>
>
> Here's a better version that allows arbitraty number lengths:
>
> #include <string_view>
> #include <compare>
> #include <type_traits>
> #include <cctype>
> #include <stdexcept>
> #include <cstdint>
> #include <cassert>
>
> template<typename CharType, typename Traits>
>     requires
>     std::is_same_v<std::make_unsigned_t<CharType>, unsigned char> ||
> std::is_same_v<CharType, wchar_t>
>     &&
>     requires( CharType const *str, size_t n ) { { Traits::compare( str,
> str, n ) } -> std::same_as<int>; }
> int numberedStrCmp( std::basic_string_view<CharType, Traits> const
> &left, std::basic_string_view<CharType, Traits> const &right )
> {
>     using str_cit = typename std::basic_string_view<CharType,
> Traits>::const_iterator;
>     str_cit itLeft = left.cbegin(), itRight = right.cbegin();
>     auto digitsCmp = [&]() -> int
>     {
>         auto nDigits = []( str_cit &it, str_cit end ) -> ptrdiff_t
>         {
>             assert(isdigit( *it ));
>             str_cit begin = it;
>             while( ++it != end && isdigit( *it ) );
>             return it - begin;
>         };
>         ptrdiff_t
>             nLeftDigits = nDigits( itLeft, left.cend() ),
>             nRightDigits = nDigits( itRight, right.cend() );
>         if( nLeftDigits != nRightDigits )
>             return nLeftDigits < nRightDigits ? -1 : 1;
>         nLeftDigits = -nLeftDigits;
>         do
>             if( itLeft[nLeftDigits] != itRight[nLeftDigits] )
>                 return itLeft[nLeftDigits] < itRight[nLeftDigits] ? -1
> : 1;
>         while( ++nLeftDigits );
>         return 0;
>     };
>     auto skipDigits = []( str_cit &it )
>     {
>         while( isdigit( *++it ) );
>     };
>     auto compareCurChar = [&]() -> int
>     {
>         bool
>             leftDigit = isdigit( *itLeft ),
>             rightDigit = isdigit( *itRight );
>         if( leftDigit && rightDigit )
>             return digitsCmp();
>         else if( leftDigit || rightDigit )
>         {
>             auto cmpDigitChar = []( CharType chr ) -> int
>             {
>                 CharType cmpDigit = '0';
>                 return Traits::compare( &cmpDigit, &chr, 1 );
>             };
>             if( leftDigit )
>             {
>                 skipDigits( itLeft );
>                 return cmpDigitChar( *itRight++ );
>             }
>             else
>             {
>                 skipDigits( itRight );
>                 return -cmpDigitChar( *itLeft++ );
>             }
>         }
>         return Traits::compare( &*itLeft++, &*itRight++, 1 );
>     };
>     for( ; ; )
>     {
>         auto zeroCmp = []( CharType chr )
>         {
>             CharType zero = '\0';
>             return Traits::compare( &zero, &chr, 1 );
>         };
>         if( itLeft == left.cend() )
>             return itRight != right.cend() ? zeroCmp( *itRight ) : 0;
>         if( itRight == right.cend() )
>             return -zeroCmp( *itLeft );
>         int cmp = compareCurChar();
>         if( cmp != 0 )
>             return cmp;
>     }
> }
>
> using namespace std;
>
> #if !defined(NDEBUG)
> template
> int numberedStrCmp( basic_string_view<char, char_traits<char>> const
> &left, basic_string_view<char, char_traits<char>> const &right );
> #endif

Re: Embedded numbers sorting function (begging post)

<sva6n2$pdj$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 10:15:15 +0100
Organization: A noiseless patient Spider
Lines: 107
Message-ID: <sva6n2$pdj$1@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9un6$9iq$1@dont-email.me> <sva63f$ktu$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Feb 2022 09:15:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="26035"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JbcedqzPfpj4524UhwdtyNoDH7T6jiN0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:SJJxD+HaK2mWgVOs+4uZXaNi5m0=
In-Reply-To: <sva63f$ktu$2@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 09:15 UTC

So this is it:

#include <string_view>
#include <compare>
#include <type_traits>
#include <cctype>
#include <stdexcept>
#include <cstdint>
#include <cassert>

template<typename CharType, typename Traits>
requires
std::is_same_v<std::make_unsigned_t<CharType>, unsigned char> ||
std::is_same_v<CharType, wchar_t>
&&
requires( CharType const *str, size_t n ) { { Traits::compare( str,
str, n ) } -> std::same_as<int>; }
int numberedStrCmp( std::basic_string_view<CharType, Traits> const
&left, std::basic_string_view<CharType, Traits> const &right )
{ using str_cit = typename std::basic_string_view<CharType,
Traits>::const_iterator;
str_cit itLeft = left.cbegin(), itRight = right.cbegin();
auto digitsCmp = [&]() -> int
{
auto skipLeadingZeroes = []( str_cit &it, str_cit end )
{
assert(isdigit( *it ));
for( ; *it == '0' && it + 1 != end && isdigit( it[1] ); ++it );
};
skipLeadingZeroes( itLeft, left.cend() );
skipLeadingZeroes( itRight, right.cend() );
auto countDigits = []( str_cit &it, str_cit end ) -> ptrdiff_t
{
assert(isdigit( *it ));
str_cit begin = it;
while( ++it != end && isdigit( *it ) );
return it - begin;
};
ptrdiff_t
nLeftDigits = countDigits( itLeft, left.cend() ),
nRightDigits = countDigits( itRight, right.cend() );
if( nLeftDigits != nRightDigits )
return nLeftDigits < nRightDigits ? -1 : 1;
ptrdiff_t nDigits = -nLeftDigits;
do
if( itLeft[nDigits] != itRight[nDigits] )
return itLeft[nDigits] < itRight[nDigits] ? -1 : 1;
while( ++nLeftDigits );
return 0;
};
auto skipDigits = []( str_cit &it )
{
assert(isdigit( *it ));
while( isdigit( *++it ) );
};
auto compareCurChar = [&]() -> int
{
bool
leftDigit = isdigit( *itLeft ),
rightDigit = isdigit( *itRight );
if( leftDigit && rightDigit )
return digitsCmp();
else if( leftDigit || rightDigit )
{
auto cmpDigitChar = []( CharType chr ) -> int
{
CharType cmpDigit = '0';
return Traits::compare( &cmpDigit, &chr, 1 );
};
if( leftDigit )
{
skipDigits( itLeft );
return cmpDigitChar( *itRight++ );
}
else
{
skipDigits( itRight );
return -cmpDigitChar( *itLeft++ );
}
}
return Traits::compare( &*itLeft++, &*itRight++, 1 );
};
for( ; ; )
{
auto zeroCmp = []( CharType chr )
{
CharType zero = '\0';
return Traits::compare( &zero, &chr, 1 );
};
if( itLeft == left.cend() )
return itRight != right.cend() ? zeroCmp( *itRight ) : 0;
if( itRight == right.cend() )
return -zeroCmp( *itLeft );
int cmp = compareCurChar();
if( cmp != 0 )
return cmp;
}
}

using namespace std;

#if !defined(NDEBUG)
template
int numberedStrCmp( basic_string_view<char, char_traits<char>> const
&left, basic_string_view<char, char_traits<char>> const &right );
#endif

Re: Embedded numbers sorting function (begging post)

<sva818$tgm5$1@news.xmission.com>

  copy mid

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

  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: Fri, 25 Feb 2022 09:37:44 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sva818$tgm5$1@news.xmission.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com> <sv9qfh$kec$1@dont-email.me> <sva1e6$tdhd$1@news.xmission.com> <sva62c$ktu$1@dont-email.me>
Injection-Date: Fri, 25 Feb 2022 09:37:44 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="967365"; 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 - Fri, 25 Feb 2022 09:37 UTC

In article <sva62c$ktu$1@dont-email.me>,
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>Am 25.02.2022 um 08:45 schrieb Kenny McCormack:
>> In article <sv9qfh$kec$1@dont-email.me>,
>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> ...
>>> You're stupid.
>>
>> That's rich. Someone posting C++ garbage in a C newsgroup, calling someone
>> else "stupid". If you keep at it, I may have to start posting my PL/I
>> solutions on these threads.
>
>C++ isn't garbage but just the more suitable langauage.
>

Like I said, you get credit for spelling "You're" correctly.

That's about it.

--
Conservatives want smaller government for the same reason criminals want fewer cops.

Re: Embedded numbers sorting function (begging post)

<3e2f2798-8649-4c48-afaa-f6ff6e0abdacn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:534e:0:b0:2d7:fd81:7e6 with SMTP id d14-20020ac8534e000000b002d7fd8107e6mr6286107qto.382.1645783382688;
Fri, 25 Feb 2022 02:03:02 -0800 (PST)
X-Received: by 2002:ac8:7fca:0:b0:2de:8f3d:89be with SMTP id
b10-20020ac87fca000000b002de8f3d89bemr6219690qtk.34.1645783382542; Fri, 25
Feb 2022 02:03:02 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 25 Feb 2022 02:03:02 -0800 (PST)
In-Reply-To: <sv9qfh$kec$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:4577:c35b:268f:6eb5;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:4577:c35b:268f:6eb5
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com> <sv9qfh$kec$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3e2f2798-8649-4c48-afaa-f6ff6e0abdacn@googlegroups.com>
Subject: Re: Embedded numbers sorting function (begging post)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Fri, 25 Feb 2022 10:03:02 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Fri, 25 Feb 2022 10:03 UTC

On Friday, 25 February 2022 at 05:46:53 UTC, Bonita Montero wrote:
> Am 24.02.2022 um 23:46 schrieb Kaz Kylheku:
>
> > You don't want to pass wide characters or other junk into isdigit!
> isdigit takes an int.
> > Even char is not safe, because it can be signed and exhibit negative
> > values that are not EOF.
> As the boundary between signed and and unsigned ints doesn't fall
> within >= '0' and <= '9' it isn't a problem that isdgit takes an int.
>
If isdigit() expands to ((ch) >= '0' && (ch) <= '9') then isdigit(c++) has
funny results.
If it expands to (__internaltable[ch+1]) then ch outside the range -1 to
255 will have funny results.

I think the standard says that the second option is to be preferred.

Re: Embedded numbers sorting function (begging post)

<87lexzb24j.fsf@bsb.me.uk>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 11:46:04 +0000
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <87lexzb24j.fsf@bsb.me.uk>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="7cff67e7e7feb80c1a54b71705efff31";
logging-data="15012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+40jufmpXiqGwEQziKZxBYku7+txOfEDk="
Cancel-Lock: sha1:I8rAc63frLcXUnWxuJflmJQkM8o=
sha1:xINGBkItAsGkiSXm6EKuPLnCs44=
X-BSB-Auth: 1.38f21d34af5415cb1d0d.20220225114604GMT.87lexzb24j.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 25 Feb 2022 11:46 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:

> Am 24.02.2022 um 23:46 schrieb Kaz Kylheku:
>
>> You don't want to pass wide characters or other junk into isdigit!
>
> isdigit takes an int.
>
>> Even char is not safe, because it can be signed and exhibit negative
>> values that are not EOF.
>
> As the boundary between signed and and unsigned ints doesn't fall
> within >= '0' and <= '9' it isn't a problem that isdgit takes an int.

You are missing the point. It's undefined. Anyway, as an advocate for
C++ you should be using the simple C++ way to do this test:

std::use_facet<std::ctype<char>>(std::locale()).is(std::ctype_base::digit, c)

;-)

--
Ben.

Re: Embedded numbers sorting function (begging post)

<svagdf$qlr$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 13:00:48 +0100
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <svagdf$qlr$1@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me>
<3e2f2798-8649-4c48-afaa-f6ff6e0abdacn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Feb 2022 12:00:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="27323"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/O3RPyC1TLkQdJFSrysX5va91pH+8G+GQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:EXj6avHTA38nW2uVfhiBROL4x0U=
In-Reply-To: <3e2f2798-8649-4c48-afaa-f6ff6e0abdacn@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 12:00 UTC

Am 25.02.2022 um 11:03 schrieb Malcolm McLean:
> On Friday, 25 February 2022 at 05:46:53 UTC, Bonita Montero wrote:
>> Am 24.02.2022 um 23:46 schrieb Kaz Kylheku:
>>
>>> You don't want to pass wide characters or other junk into isdigit!
>> isdigit takes an int.
>>> Even char is not safe, because it can be signed and exhibit negative
>>> values that are not EOF.
>> As the boundary between signed and and unsigned ints doesn't fall
>> within >= '0' and <= '9' it isn't a problem that isdgit takes an int.
>>
> If isdigit() expands to ((ch) >= '0' && (ch) <= '9') then isdigit(c++) has
> funny results.

It doesn't matter if the digits I handle to isdigit are sign-expanded
or not because '0' ... '9' falls into the unsigned range.

> If it expands to (__internaltable[ch+1]) then ch outside the range -1 to
> 255 will have funny results.
>
> I think the standard says that the second option is to be preferred.

Re: Embedded numbers sorting function (begging post)

<svagep$qlr$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 13:01:30 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <svagep$qlr$2@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me> <87lexzb24j.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Feb 2022 12:01:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="27323"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18f+iqnNoFn0DQlJhQzZ9u7qITLYPrUwkY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:GkTRTVw8HjACicZrNCiXYtQ78dQ=
In-Reply-To: <87lexzb24j.fsf@bsb.me.uk>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 12:01 UTC

Am 25.02.2022 um 12:46 schrieb Ben Bacarisse:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>
>> Am 24.02.2022 um 23:46 schrieb Kaz Kylheku:
>>
>>> You don't want to pass wide characters or other junk into isdigit!
>>
>> isdigit takes an int.
>>
>>> Even char is not safe, because it can be signed and exhibit negative
>>> values that are not EOF.
>>
>> As the boundary between signed and and unsigned ints doesn't fall
>> within >= '0' and <= '9' it isn't a problem that isdgit takes an int.
>
> You are missing the point. It's undefined. Anyway, as an advocate for
> C++ you should be using the simple C++ way to do this test:

There's nothing undefined here. It doesn't matter if the digits I
handle to isdigit are sign-expanded or not because '0' ... '9'
falls into the unsigned range.

Re: Embedded numbers sorting function (begging post)

<svagga$qlr$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 13:02:19 +0100
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <svagga$qlr$3@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me> <87lexzb24j.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Feb 2022 12:02:18 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="27323"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184krNyIuqNu4zMa2bUOcd4fsY56HPepUI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:CH5dvOvU0jiCUsxgBBGacZgJf9k=
In-Reply-To: <87lexzb24j.fsf@bsb.me.uk>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 12:02 UTC

Am 25.02.2022 um 12:46 schrieb Ben Bacarisse:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>
>> Am 24.02.2022 um 23:46 schrieb Kaz Kylheku:
>>
>>> You don't want to pass wide characters or other junk into isdigit!
>>
>> isdigit takes an int.
>>
>>> Even char is not safe, because it can be signed and exhibit negative
>>> values that are not EOF.
>>
>> As the boundary between signed and and unsigned ints doesn't fall
>> within >= '0' and <= '9' it isn't a problem that isdgit takes an int.
>
> You are missing the point. It's undefined. Anyway, as an advocate for
> C++ you should be using the simple C++ way to do this test:
>
> std::use_facet<std::ctype<char>>(std::locale()).is(std::ctype_base::digit, c)

And _digit_-checking needs no locales for sure.

Re: Embedded numbers sorting function (begging post)

<B07SJ.40378$8V_7.19162@fx04.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx04.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> <sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com> <sv9qfh$kec$1@dont-email.me> <sva1e6$tdhd$1@news.xmission.com>
Lines: 11
Message-ID: <B07SJ.40378$8V_7.19162@fx04.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 25 Feb 2022 15:58:25 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 25 Feb 2022 15:58:25 GMT
X-Received-Bytes: 1208
 by: Scott Lurndal - Fri, 25 Feb 2022 15:58 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:
>In article <sv9qfh$kec$1@dont-email.me>,
>Bonita Montero <Bonita.Montero@gmail.com> wrote:
>...
>>You're stupid.
>

>That said, gotta give ya credit for spelling "You're" correctly. Most
>folks of your general IQ level would have misspelled it.

That's more due to ESL (English as a Second Language) than to IQ, I suspect.

Re: Embedded numbers sorting function (begging post)

<eb52bd77-66ac-432d-9663-019dbc621e1bn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:f2f:b0:432:c4c9:9953 with SMTP id iw15-20020a0562140f2f00b00432c4c99953mr2718667qvb.113.1645810662045;
Fri, 25 Feb 2022 09:37:42 -0800 (PST)
X-Received: by 2002:a05:6214:e85:b0:432:e2e4:c1cb with SMTP id
hf5-20020a0562140e8500b00432e2e4c1cbmr777797qvb.59.1645810661878; Fri, 25 Feb
2022 09:37:41 -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: Fri, 25 Feb 2022 09:37:41 -0800 (PST)
In-Reply-To: <svagga$qlr$3@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:4577:c35b:268f:6eb5;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:4577:c35b:268f:6eb5
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me> <87lexzb24j.fsf@bsb.me.uk> <svagga$qlr$3@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <eb52bd77-66ac-432d-9663-019dbc621e1bn@googlegroups.com>
Subject: Re: Embedded numbers sorting function (begging post)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Fri, 25 Feb 2022 17:37:42 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 7
 by: Malcolm McLean - Fri, 25 Feb 2022 17:37 UTC

On Friday, 25 February 2022 at 12:02:56 UTC, Bonita Montero wrote:
> Am 25.02.2022 um 12:46 schrieb Ben Bacarisse:
>
> > std::use_facet<std::ctype<char>>(std::locale()).is(std::ctype_base::digit, c)
> And _digit_-checking needs no locales for sure.
>
In Arabic, whilst they use Arabic numerals (of course), the glyphs are very
different from the ones used in the West.

Re: Embedded numbers sorting function (begging post)

<20220225103913.880@kylheku.com>

  copy mid

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

  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: Fri, 25 Feb 2022 18:57:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 87
Message-ID: <20220225103913.880@kylheku.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me>
Injection-Date: Fri, 25 Feb 2022 18:57:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="46f490ff7610d9fc4fe62d15feeaa4fc";
logging-data="15034"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QL5yJh2cHOCk/AJ4UpQ9/I3NJ3ni2u4c="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:aztuGpvPHHbFQDBnkZVIFRX2ECc=
 by: Kaz Kylheku - Fri, 25 Feb 2022 18:57 UTC

On 2022-02-25, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 24.02.2022 um 23:46 schrieb Kaz Kylheku:
>
>> You don't want to pass wide characters or other junk into isdigit!
>
> isdigit takes an int.

Good, you can read manuals. It takes an int, which ISO C says must
either represent the value EOF, or else a value in the range of the
unsigned char type (0 to UCHAR_MAX).

Passing any other value is undefined behavior. That's exactly what will
happen when you feed it wchar_t values containing character code points
whose values lie beyond UCHAR_MAX, or that are negative values not equal
to EOF after conversion to int.

>> Even char is not safe, because it can be signed and exhibit negative
>> values that are not EOF.
>
> As the boundary between signed and and unsigned ints doesn't fall
> within >= '0' and <= '9' it isn't a problem that isdgit takes an int.

What???

If you know that the datum is between '0' and '9', why would you be
calling isdigit?

you're calling isdigit because you don't know what.

What I mean is that if you have a C string str made up of char elements,
which is often the case, then isdigit(str[i]) is not necessary
well-defined behavior. While all the positive valuews of char will be
within the 0 to UCHAR_MAX range, char may be signed, and so str[i] could
produce a value that is negative and not EOF. Then isdigit's behavior is
no longer defined.

>> You have to be careful how you convert a char to a wchar. If a char value is,
>> say, -128, you don't want to just be casting that to wchar_t because you will
>> get some huge value. Rather, you want something like
>> (wchar_t) (unsigned char) c.
>
> You're stupid.

It may seem like that to you, but the situation is more like that
I might not be very good at explaining things to people who don't have
anywhere near the right comprehension level.

What I mean in the above paragraph is that, suppose we have some
ISO-Latin character value that maps to a negative value of char.
For instance, the 0xA0 space character. In signed char (on 8 bit, two's
complement platforms) that will have the value -96.

What happens if we call iswdigit(-96)? Internally, this function cuold
treat that as, say, an unsigned 32 bit value: i.e. 0xFFFFFFA0 which
doesn't correspond to the character. (That garbage could well somehow be
misinterpreted as a digit, resulting in a false positive.)

What my "stupid" cast is doing is this:

(wchar_t) (unsigned char) -96.
^^^^^^^^^^^^^^^^^^^^
the underlined part goes to 160, and so now if we pass that to iswdigit,
it will be operating on the 160 value that we intend.

But in the wchar_t expansion of all the C++ template-ology, we don't
want that (unsigned char) cast, of ourse; it will be truncating the wide
characters.

>> Someone just wanted a nicer sort for displaying file names; now
>> you're killing the program with a surprise exception when someone has
>> a file name with too many consecutive digits somewhere in it.
>
> Then you need additional handling inside an exception-handler.

If you don't document that, it won't get written, and it won't get
tested. The first person to step on that case could be an end user
who creates a filename with many digits in it.

Furthermore, a comparison function for sorting strings must handle all
strings you can throw at it without crashing, aborting or throwing.

It's not reasonable for any filename handling code to throw when it is
given a valid filename.

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

Re: Embedded numbers sorting function (begging post)

<20220225105747.427@kylheku.com>

  copy mid

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

  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: Fri, 25 Feb 2022 18:58:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <20220225105747.427@kylheku.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me> <sva1e6$tdhd$1@news.xmission.com>
<sva62c$ktu$1@dont-email.me>
Injection-Date: Fri, 25 Feb 2022 18:58:01 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="46f490ff7610d9fc4fe62d15feeaa4fc";
logging-data="15034"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+6OGizcAJXX41M6ZQ1LKUIBCjf2aO0o4="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:fX9+nfZbe7cuue5OTK7DsPbOlCE=
 by: Kaz Kylheku - Fri, 25 Feb 2022 18:58 UTC

On 2022-02-25, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 25.02.2022 um 08:45 schrieb Kenny McCormack:
>> In article <sv9qfh$kec$1@dont-email.me>,
>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> ...
>>> You're stupid.
>>
>> That's rich. Someone posting C++ garbage in a C newsgroup, calling someone
>> else "stupid". If you keep at it, I may have to start posting my PL/I
>> solutions on these threads.
>
> C++ isn't garbage but just the more suitable langauage.

Not in your hands, though.

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

Re: Embedded numbers sorting function (begging post)

<20220225110252.132@kylheku.com>

  copy mid

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

  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: Fri, 25 Feb 2022 19:12:42 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <20220225110252.132@kylheku.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me> <87lexzb24j.fsf@bsb.me.uk>
<svagga$qlr$3@dont-email.me>
<eb52bd77-66ac-432d-9663-019dbc621e1bn@googlegroups.com>
Injection-Date: Fri, 25 Feb 2022 19:12:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="46f490ff7610d9fc4fe62d15feeaa4fc";
logging-data="15034"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TkcNjuHGWtSN+gHhIP1gJNQGsFLTnCtQ="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:VahGGly72iBYpSc3KBRMs/lq9ys=
 by: Kaz Kylheku - Fri, 25 Feb 2022 19:12 UTC

On 2022-02-25, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
> On Friday, 25 February 2022 at 12:02:56 UTC, Bonita Montero wrote:
>> Am 25.02.2022 um 12:46 schrieb Ben Bacarisse:
>>
>> > std::use_facet<std::ctype<char>>(std::locale()).is(std::ctype_base::digit, c)
>> And _digit_-checking needs no locales for sure.
>>
> In Arabic, whilst they use Arabic numerals (of course), the glyphs are very
> different from the ones used in the West.

Is't not clear, however, whether the ISO C isdigit and iswdigit
functions are allowed to detect those.

The requirement is that they only report true for the ten decimal digits
of the basic execution character set.

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

Re: Embedded numbers sorting function (begging post)

<87ilt2oiw8.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 11:17:43 -0800
Organization: None to speak of
Lines: 36
Message-ID: <87ilt2oiw8.fsf@nosuchdomain.example.com>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me>
<3e2f2798-8649-4c48-afaa-f6ff6e0abdacn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="4430882ee1cf9bb3d1ca67a3a8faec21";
logging-data="26180"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18RRJzAZef+xQM8yTmoRIOU"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:IQTXN8yTHpeD9pKKvb0o+r7/fEo=
sha1:9QP/trX+yavBZcze7VzWDDRaIoc=
 by: Keith Thompson - Fri, 25 Feb 2022 19:17 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> On Friday, 25 February 2022 at 05:46:53 UTC, Bonita Montero wrote:
>> Am 24.02.2022 um 23:46 schrieb Kaz Kylheku:
>>
>> > You don't want to pass wide characters or other junk into isdigit!
>> isdigit takes an int.
>> > Even char is not safe, because it can be signed and exhibit negative
>> > values that are not EOF.
>> As the boundary between signed and and unsigned ints doesn't fall
>> within >= '0' and <= '9' it isn't a problem that isdgit takes an int.
>>
> If isdigit() expands to ((ch) >= '0' && (ch) <= '9') then isdigit(c++) has
> funny results.
> If it expands to (__internaltable[ch+1]) then ch outside the range -1 to
> 255 will have funny results.
>
> I think the standard says that the second option is to be preferred.

Not just preferred, required. N1570 7.1.4p1:

Any invocation of a library function that is implemented as a
macro shall expand to code that evaluates each of its arguments
exactly once, fully protected by parentheses where necessary, so
it is generally safe to use arbitrary expressions as arguments.

But calling isdigit with a value that is not either EOF or within the
range of unsigned char has undefined behavior, which is why you need to
do something like:

char c = ...;
isdigit((unsigned char)c);

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Embedded numbers sorting function (begging post)

<KgaSJ.21190$oF2.769@fx10.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx10.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.6.1
Subject: Re: Embedded numbers sorting function (begging post)
Content-Language: en-US
Newsgroups: comp.lang.c
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me> <87lexzb24j.fsf@bsb.me.uk>
<svagga$qlr$3@dont-email.me>
<eb52bd77-66ac-432d-9663-019dbc621e1bn@googlegroups.com>
<20220225110252.132@kylheku.com>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <20220225110252.132@kylheku.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 28
Message-ID: <KgaSJ.21190$oF2.769@fx10.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Fri, 25 Feb 2022 14:40:26 -0500
X-Received-Bytes: 2519
 by: Richard Damon - Fri, 25 Feb 2022 19:40 UTC

On 2/25/22 2:12 PM, Kaz Kylheku wrote:
> On 2022-02-25, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
>> On Friday, 25 February 2022 at 12:02:56 UTC, Bonita Montero wrote:
>>> Am 25.02.2022 um 12:46 schrieb Ben Bacarisse:
>>>
>>>> std::use_facet<std::ctype<char>>(std::locale()).is(std::ctype_base::digit, c)
>>> And _digit_-checking needs no locales for sure.
>>>
>> In Arabic, whilst they use Arabic numerals (of course), the glyphs are very
>> different from the ones used in the West.
>
> Is't not clear, however, whether the ISO C isdigit and iswdigit
> functions are allowed to detect those.
>
> The requirement is that they only report true for the ten decimal digits
> of the basic execution character set.
>

While the character classification routines allow for locale specific
letters and such, it doesn't have similar wording for digits.

This would imply that isdigit is supposed to ONLY detect for the
characters '0' ... '9' and not other 'digits' from other locales.

Since the rules for character sets are written to allow the use of the
expression c - '0' to convert a character in c that passes an isdigit
test to its decimal value, I strongly suspect that limitation is
intentional and not just an omission.

Re: Embedded numbers sorting function (begging post)

<svbd0k$ne4$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 21:08:53 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <svbd0k$ne4$2@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me> <sva1e6$tdhd$1@news.xmission.com>
<sva62c$ktu$1@dont-email.me> <20220225105747.427@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Feb 2022 20:08:52 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="24004"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+L497rZaoG/AA7M1MQW7WZ0yNeUMLY/HA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:3OwFMI8wdHValf+3pKUQacH++Ro=
In-Reply-To: <20220225105747.427@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 20:08 UTC

Am 25.02.2022 um 19:58 schrieb Kaz Kylheku:
> On 2022-02-25, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Am 25.02.2022 um 08:45 schrieb Kenny McCormack:
>>> In article <sv9qfh$kec$1@dont-email.me>,
>>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>> ...
>>>> You're stupid.
>>>
>>> That's rich. Someone posting C++ garbage in a C newsgroup, calling someone
>>> else "stupid". If you keep at it, I may have to start posting my PL/I
>>> solutions on these threads.
>>
>> C++ isn't garbage but just the more suitable langauage.
>
> Not in your hands, though.

You're simply stupid.

Re: Embedded numbers sorting function (begging post)

<svbd3b$ne4$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Embedded numbers sorting function (begging post)
Date: Fri, 25 Feb 2022 21:10:21 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <svbd3b$ne4$3@dont-email.me>
References: <0865bc76-8d80-43c1-af79-87c3faf7c9d9n@googlegroups.com>
<sv8tlj$i1l$1@dont-email.me> <20220224141441.215@kylheku.com>
<sv90fi$5gl$1@dont-email.me> <20220224142724.547@kylheku.com>
<sv9qfh$kec$1@dont-email.me>
<3e2f2798-8649-4c48-afaa-f6ff6e0abdacn@googlegroups.com>
<87ilt2oiw8.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 25 Feb 2022 20:10:19 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0687686a4bc6cb218a47242c55ee5217";
logging-data="24004"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0CcVokDbOgQaL7LighsfcsYBHp0hSXkQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Cancel-Lock: sha1:iPon0AjL6hJjfIYamgUJ+KO0jOk=
In-Reply-To: <87ilt2oiw8.fsf@nosuchdomain.example.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 25 Feb 2022 20:10 UTC

Am 25.02.2022 um 20:17 schrieb Keith Thompson:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>> On Friday, 25 February 2022 at 05:46:53 UTC, Bonita Montero wrote:
>>> Am 24.02.2022 um 23:46 schrieb Kaz Kylheku:
>>>
>>>> You don't want to pass wide characters or other junk into isdigit!
>>> isdigit takes an int.
>>>> Even char is not safe, because it can be signed and exhibit negative
>>>> values that are not EOF.
>>> As the boundary between signed and and unsigned ints doesn't fall
>>> within >= '0' and <= '9' it isn't a problem that isdgit takes an int.
>>>
>> If isdigit() expands to ((ch) >= '0' && (ch) <= '9') then isdigit(c++) has
>> funny results.
>> If it expands to (__internaltable[ch+1]) then ch outside the range -1 to
>> 255 will have funny results.
>>
>> I think the standard says that the second option is to be preferred.
>
> Not just preferred, required. N1570 7.1.4p1:
>
> Any invocation of a library function that is implemented as a
> macro shall expand to code that evaluates each of its arguments
> exactly once, fully protected by parentheses where necessary, so
> it is generally safe to use arbitrary expressions as arguments.
>
> But calling isdigit with a value that is not either EOF or within the
> range of unsigned char has undefined behavior, which is why you need to
> do something like:

My code is C++ and C++ specifies isdigit as a normal function.

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor