uChar() (Char() for unicode)

Share your advanced PureBasic knowledge/code with the community.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

uChar() (Char() for unicode)

Post by Num3 »

Tip by Danilo on the IRC...

Code: Select all

CompilerIf #PB_Compiler_Unicode
  Procedure.s uChr(char)
    char$ = " "
    PokeW(@char$, char & $FFFF)
    ProcedureReturn char$
  EndProcedure
  Macro Chr(x)
    uChr(x)
  EndMacro
CompilerEndIf

A$ = "test " + Chr($20AC) + " " + Chr($FB30)
Debug a$
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

What's wrong with Chr()? It should work in unicode mode.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Trond wrote:What's wrong with Chr()? It should work in unicode mode.
Doesn't work...

Seems none of the string functions are working :shock:
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Then you have a big problem.. Your source has to be in utf8 format when using unicode constants.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

...when your source is in UTF-8 and Create Unicode Exe is on, Chr() works with 2byte....

or has this been changed again?
oh... and have a nice day.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

The manual says:
When developing a unicode program, it's recommended to set the IDE in UTF-8 mode, so all the source files will be unicode ready.
Maybe the statement should be rephrased :P
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

I have my IDE default set to utf-8, why should i use ascii??? :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

ts-soft wrote:I have my IDE default set to utf-8, why should i use ascii??? :wink:
Because it's the default that comes with PB...
I think 90% of us didn't even bother to change that :D
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

The string functions should work with unicode characters even when the source is set to ascii. You just have to generate those characters at run-time or read them from a file, as you obviously can't have unicode characters in an ascii file.

I'd vote for just dropping the ascii mode altogether, as UTF-8 is mostly backwards compatible with it, unless you use special characters, in which case you couldn't have used ascii anyways.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

my favourite now:

+1
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

ansi-mode, not ascii mode :wink:
but you are right, the ansi-mode is needless
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

ts-soft wrote:ansi-mode, not ascii mode :wink:
:shock: Are you sure? ANSI defines only the first 128 characters, while PB uses all 256 in plain text mode. How could that possibly be called an ANSI mode?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

ASCII is orginal 7-Bit Code, ANSI is 8-Bit, but the official norm is:
ISO/IEC 8859
but i'm no 100% sure :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Nowadays, when someone says ASCII he is usually referring to Extended-ASCII.

By the way, just now i realize that a macro can have the same name as a internal function. I remember to do that in the past (i.e. using older PB versions) but it didn't work :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Psychophanta wrote: By the way, just now i realize that a macro can have the same name as a internal function. I remember to do that in the past (i.e. using older PB versions) but it didn't work :?
Is this now legal syntax indeed, one that we can count on to be available in future PB-releases?
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Post Reply