Page 1 of 2
uChar() (Char() for unicode)
Posted: Tue Jun 10, 2008 6:14 pm
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$
Posted: Tue Jun 10, 2008 6:34 pm
by Trond
What's wrong with Chr()? It should work in unicode mode.
Posted: Tue Jun 10, 2008 6:44 pm
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

Posted: Tue Jun 10, 2008 7:00 pm
by Fred
Then you have a big problem.. Your source has to be in utf8 format when using unicode constants.
Posted: Tue Jun 10, 2008 7:18 pm
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?
Posted: Tue Jun 10, 2008 7:25 pm
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

Posted: Tue Jun 10, 2008 7:29 pm
by ts-soft
I have my IDE default set to utf-8, why should i use ascii???

Posted: Tue Jun 10, 2008 7:37 pm
by Num3
ts-soft wrote:I have my IDE default set to utf-8, why should i use ascii???

Because it's the default that comes with PB...
I think 90% of us didn't even bother to change that

Posted: Tue Jun 10, 2008 7:44 pm
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.
Posted: Tue Jun 10, 2008 7:51 pm
by Num3
my favourite now:
+1
Posted: Tue Jun 10, 2008 7:58 pm
by ts-soft
ansi-mode, not ascii mode
but you are right, the ansi-mode is needless
Posted: Wed Jun 11, 2008 10:14 am
by Trond
ts-soft wrote:ansi-mode, not ascii mode

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?
Posted: Wed Jun 11, 2008 10:28 am
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

Posted: Wed Jun 11, 2008 10:50 pm
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

Posted: Thu Jun 12, 2008 7:25 am
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?