Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-04

Unicode characters in source code

10 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

If I want to use Unicode characters in my source code, but without actually typing in the Unicode character - I rather want to define it similar to ASCII chars or Hex values:
eg: Char(65) or 'test'+#65+'me'
or similar to what hex values are defined with a dollar prefix: $30

Any idea how I can do this? I don't want to mess with the -Fcutf8 compiler parameter if I can avoid it. I also want the ability of the source code to be edited by a editor that might not support Unicode (more precisely UTF-8).

Is this possible?

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

ik
to Graeme Geldenhuys

http://ik.homelinux.org/

Graeme Geldenhuys wrote 13 lines
Hi, If I want to use Unicode characters in my source code, but without actually typing in the Unicode character - I rather want to define it similar to ASCII chars or Hex values: eg: Char(65) or 'test'+#65+'me' or similar to what hex values are defined with a dollar prefix: $30 Any idea how I can do this? I don't want to mess with the -Fcutf8 compiler parameter if I can avoid it. I also want the ability of the source code to be edited by a editor that might not support Unicode (more precisely UTF-8).

$#50D helps you ? :)

You can also break it into two/four bytes like so : #404#500

Show quoted text 15 lines
Is this possible? Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Ido

Reply by email

ik
to Graeme Geldenhuys

http://ik.homelinux.org/

Graeme Geldenhuys wrote 9 lines
ik het geskryf: > $#50D helps you ? :) > > You can also break it into two/four bytes like so : #404#500 Perfect, thank you.

You can also take a look at this old code of mine: http://ik.homelinux.org/projects/files/hebtoeng-0.1.tar.gz Florian fixed a bug in FPC due to this program regarding unicode :)

Show quoted text 13 lines
Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Ido

Reply by email

Tomas Hajny
to ik: http://ik.homelinux.org/ $#50D helps you ? :) You can also break it into two/four bytes…

On Wed, April 21, 2010 10:47, ik wrote:

Hi,

Show quoted text 10 lines
> If I want to use Unicode characters in my source code, but without > actually > typing in the Unicode character - I rather want to define it similar to > ASCII chars or Hex values: > eg: Char(65) or 'test'+#65+'me' > or similar to what hex values are defined with a dollar prefix: $30 > > Any idea how I can do this? I don't want to mess with the -Fcutf8 > compiler > parameter if I can avoid it. I also want the ability of the source code

.
.

What do you mean by "messing with the -Fcutf8 parameter"? If you include some character constants outside the us-ascii set, you should always tell the compiler how to evaluate them, because the evaluation depends on the used encoding; especially if you intend to use those for Unicode specific types (characters or strings). The only alternative not requiring the compiler to evaluate the constants using certain encoding would be something like using the internally expected format and putting the values there directly as sequence of bytes using e.g. an absolute construct mapped to the same memory area, but that is probably neither efficient nor very wise considering necessity to rely on compiler internals...

Tomas

Reply by email

Graeme Geldenhuys
to ik: http://ik.homelinux.org/ You can also take a look at this old code of mine:…

ik het geskryf:

You can also take a look at this old code of mine: http://ik.homelinux.org/projects/files/hebtoeng-0.1.tar.gz Florian fixed a bug in FPC due to this program regarding unicode :)

I needed UTF-8 format to work with fpGUI, and the #xx format works perfectly, but I'll take a look at your code anyway. In what version of FPC was the bug fixed? v2.5.1 or v2.4.1? The program I am writing needs to work with latest stable FPC.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

ik
to Graeme Geldenhuys

http://ik.homelinux.org/

Graeme Geldenhuys wrote 11 lines
ik het geskryf: > > You can also take a look at this old code of mine: > http://ik.homelinux.org/projects/files/hebtoeng-0.1.tar.gz > Florian fixed a bug in FPC due to this program regarding unicode :) I needed UTF-8 format to work with fpGUI, and the #xx format works perfectly, but I'll take a look at your code anyway. In what version of FPC was the bug fixed? v2.5.1 or v2.4.1? The program I am writing needs to work with latest stable FPC.

It was fixed on 2.,2x i think, it was in 2008 or something like that ...

Show quoted text 13 lines
Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Ido

Reply by email

Mattias Gärtner
to Tomas Hajny: . . What do you mean by "messing with the -Fcutf8 parameter"? If you include some…

Zitat von Tomas Hajny :

Show quoted text 15 lines
On Wed, April 21, 2010 10:47, ik wrote: Hi, >> If I want to use Unicode characters in my source code, but without >> actually >> typing in the Unicode character - I rather want to define it similar to >> ASCII chars or Hex values: >> eg: Char(65) or 'test'+#65+'me' >> or similar to what hex values are defined with a dollar prefix: $30 >> >> Any idea how I can do this? I don't want to mess with the -Fcutf8 >> compiler >> parameter if I can avoid it. I also want the ability of the source code
Caption:=#$C3#$A4; // a umlaut
Show quoted text 12 lines
. What do you mean by "messing with the -Fcutf8 parameter"? If you include some character constants outside the us-ascii set, you should always tell the compiler how to evaluate them, because the evaluation depends on the used encoding; especially if you intend to use those for Unicode specific types (characters or strings). The only alternative not requiring the compiler to evaluate the constants using certain encoding would be something like using the internally expected format and putting the values there directly as sequence of bytes using e.g. an absolute construct mapped to the same memory area, but that is probably neither efficient nor very wise considering necessity to rely on compiler internals...

Mattias

Reply by email

Graeme Geldenhuys
to Tomas Hajny: . . What do you mean by "messing with the -Fcutf8 parameter"? If you include some…

Tomas Hajny het geskryf:

What do you mean by "messing with the -Fcutf8 parameter"? If you include some character constants outside the us-ascii set, you should always tell the compiler how to evaluate them, because the evaluation depends on the

fpGUI uses UTF-8 internally on all platforms. Specifying some Unicode characters as a sequence of bytes stored inside an TfpgString type (alias for AnsiString) causes no problems with FPC. To the compiler it's simply a sequence of bytes. fpGUI has it's one UTF-8 file and string manipulation functions.

The usage of #xxxx format also overcomes some problems with editors not fully supporting Unicode or when you use a non-Unicode font in your editor. For example, I use a non-Unicode font (Raize) under Linux with Lazarus IDE. If I try and insert true Unicode characters inside the editor, things screw-up and text is garbled.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Tomas Hajny
to Graeme Geldenhuys
Graeme Geldenhuys wrote 12 lines
Tomas Hajny het geskryf: > > What do you mean by "messing with the -Fcutf8 parameter"? If you include > some character constants outside the us-ascii set, you should always > tell > the compiler how to evaluate them, because the evaluation depends on the fpGUI uses UTF-8 internally on all platforms. Specifying some Unicode characters as a sequence of bytes stored inside an TfpgString type (alias for AnsiString) causes no problems with FPC. To the compiler it's simply a sequence of bytes. fpGUI has it's one UTF-8 file and string manipulation functions.

This is the important part which was missing in your original message - you don't use Unicode specific types (UnicodeChar, UnicodeString, UTF8String, etc.). As mentioned in my e-mail, my comment was primarily related to using these types. Obviously, if you use a type which is "transparent" from this point of view, everything is up to you.

Show quoted text 7 lines
The usage of #xxxx format also overcomes some problems with editors not fully supporting Unicode or when you use a non-Unicode font in your editor. For example, I use a non-Unicode font (Raize) under Linux with Lazarus IDE. If I try and insert true Unicode characters inside the editor, things screw-up and text is garbled.

Yes, the alternative notation solves that problem indeed.

Tomas

Reply by email