please remove range test from chr()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

please remove range test from chr()

Post by idle »

please remove range test in the ide from chr()
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: please remove range test from chr()

Post by Fred »

The range between $D800 and $DFFF is reserved for surrogate characters, so it shouldnt be used in Chr() as it doesnt returns a valid character.
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: please remove range test from chr()

Post by idle »

Please make it a soft warning rather than a compiler halt if you feel it's important. I only mentioned it as
It broke my 4000 line utf16 module.
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: please remove range test from chr()

Post by normeus »

+1 for a warning instead of a fail

Norm
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: please remove range test from chr()

Post by Fred »

Could you explain why you need it to work as it doesn't return a valid character ? The error was added to spot this issue as a bug report was raised saying Chr() didn't work as expected.
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: please remove range test from chr()

Post by STARGÅTE »

I think the test range was added, because Len(Chr($D800)) has given 2 instead of 1.
I any way didn't use Chr() since it doesn't work with the whole unicode character range up to $10FFFF.

However:
Fred wrote: Mon Oct 16, 2023 10:25 pm The range between $D800 and $DFFF is reserved for surrogate characters, so it shouldnt be used in Chr() as it doesnt returns a valid character.
Based on this argument, you then should also check for other invalid characters like U+FFFE and U+FFFF or the NUL character, because it gives no string.

To generate surrogate pairs one can use PeekS() on a buffer with 4 bytes (the surrogate pair).
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: please remove range test from chr()

Post by idle »

It does work for the whole unicode range with utf16 encoding which you can build on top of ucs2, which is how made the utf16 module.
I was just puzzled why and for what purpose. My understanding is that It's not the function chr place to check its the final render that's supposed to check and replace non printable chrs with □
Post Reply