Sign in Join

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

Mailing lists / fpc-pascal / 2010-09

Compile ANSI unit as UTF8

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Zaher Dirkey

Hi,

I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler to convert it to utf8 before compile it?

Thanks in advance

Zaher Dirkey
ik
to Zaher Dirkey

You can use {$codepage utf8} I think, but if you are using ISO8859-6 (Arabic right ?) then I'm not sure that it will convert it, but rater treat it as a UTF-8

Ido

Zaher Dirkey wrote 14 lines
Hi, I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler to convert it to utf8 before compile it? Thanks in advance -- Zaher Dirkey _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Felipe Monteiro de Carvalho
to Zaher Dirkey: I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler…
Zaher Dirkey wrote
I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler to convert it to utf8 before compile it?

By saying that the unit has ansi strings do you mean that is has some types like:

X: ansistring;

Or that the text of the unit itself is in an iso encoding?

For the second case probably using a editor which can convert between encodings like Notepad++ would solve the issue. You can use it to convert your unit to UTF-8.

Felipe Monteiro de Carvalho
Jonas Maebe
to Zaher Dirkey: I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler…
Zaher Dirkey wrote
I have unit with Ansi strings but i want to compile it as UTF-8 how to ask the compiler to convert it to utf8 before compile it?

The compiler itself can only convert from utf-8 and several ISO code pages into utf-16 at compile time (i.e., change string constants into widestring constants). If you want to convert them to utf-8, you have to use a text editor as Felipe mentioned.

Jonas

Zaher Dirkey
to Jonas Maebe
Jonas Maebe wrote 13 lines
On 06 Sep 2010, at 01:28, Zaher Dirkey wrote: I have unit with Ansi strings but i want to compile it as UTF-8 how to ask > the compiler to convert it to utf8 before compile it? > The compiler itself can only convert from utf-8 and several ISO code pages into utf-16 at compile time (i.e., change string constants into widestring constants). If you want to convert them to utf-8, you have to use a text editor as Felipe mentioned.

Becuase i use this unit in Delphi 7 and Lazarus with my local language.

What for -Fm<x> parameters?

Thanks

Zaher Dirkey
Jonas Maebe
to Zaher Dirkey: Becuase i use this unit in Delphi 7 and Lazarus with my local language. What for -Fm<x>…
Zaher Dirkey wrote 15 lines
On Mon, Sep 6, 2010 at 11:16 AM, Jonas Maebe < >wrote: > The compiler itself can only convert from utf-8 and several ISO > code pages > into utf-16 at compile time (i.e., change string constants into > widestring > constants). If you want to convert them to utf-8, you have to use a > text > editor as Felipe mentioned. > Becuase i use this unit in Delphi 7 and Lazarus with my local language. What for -Fm<x> parameters?

Those tell the compiler that your source has been stored in that particular code page, and then the compiler will convert all string constants *from* the specified code page *to* widestring (which then at run time is converted back to the active ANSI code page; not to UTF-8).

If you want to do that, you have to wrap all your string constants with utf8encode(). That takes a widestring as parameter and returns an UTF-8 string. However, that is not Delphi-compatible either.

In the long term, native utf8string support will solve your problem, but right now what you want is not possible afaik.

Jonas

Felipe Monteiro de Carvalho
to Zaher Dirkey: Yes it is Arabic in Windows Win1256, but {$codepage utf8} not worked, it is give me…

In the Virtual Magnifying Glass I used the following solution:

1> All my strings come from a translations manager

2> When they are updated (because the user selected a different language for example) then I also added the following code:

{$ifndef fpc}
 <<-- here convert all utf-8 strings to ansi for Delphi usage
{$endif}

And now it works fine.

Check: http://magnifier.svn.sourceforge.net/viewvc/magnifier/trunk/translationsvmg.pas?revision=193&view=markup

procedure TTranslations.UpdateTranslations;
Felipe Monteiro de Carvalho