Re: [fpc-pascal] SetCodePage in older FPC 3.0.4

2019-05-28 Thread Jonas Maebe

On 2019-05-29 00:58, Alexey Tor. wrote:

I am making small unit https://github.com/alexey-t/aencoding

so I need to know:

a) will it work on FPC 3.0.4? do I need to use {$ifdef}?


It will probably (not) work the same under FPC 3.0.4 and trunk. No 
guarantees though.



b) my trick to set CP_UTF8 at the end of FromTo function is ok?


It's not ok. It will at leas break when trying to write such a string, 
or when assigning it to a unicodestring or widestring, or when assigning 
it to a typed ansistring with a different code page than UTF-8 or 
DefaultSystemCodePage.



c) what encoding numbers (e.g. 936, 950) exist in FPC 3.3 but didn't
exist in FPC 3.0.4?


FPC generally uses system library functions for the conversion, so it 
does not depend on the FPC version. The only exception is if you use the 
fpwidestring unit. In that case, the supported code pages depend on 
which extra units from packages/rtl-unicode you include. I don't know 
which code page(s) it supports by default.



Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] SetCodePage in older FPC 3.0.4

2019-05-28 Thread Alexey Tor.

I am making small unit https://github.com/alexey-t/aencoding

so I need to know:

a) will it work on FPC 3.0.4? do I need to use {$ifdef}?

b) my trick to set CP_UTF8 at the end of FromTo function is ok?

c) what encoding numbers (e.g. 936, 950) exist in FPC 3.3 but didn't 
exist in FPC 3.0.4?


--
Regards,
Alexey

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Using docker to build software

2019-05-28 Thread leledumbo via fpc-pascal
> I am curious to know if there is someone out there that have tried to 
> use Docker (https://www.docker.com) containers to build fpc applications? 

Search docker hub, you will find a lot of them, either fpc only, with
lazarus, single target or even cross compiling ready.



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Using docker to build software

2019-05-28 Thread Torsten Bonde Christiansen

Hi List.

I am curious to know if there is someone out there that have tried to 
use Docker (https://www.docker.com) containers to build fpc applications?


I have 3 applications in a suite that I am thinking of experimenting 
with, see if I can create an image containing eg. Ubuntu linux, FPC, 
Lazarus and dependencies.


But if you have tried this before success or not, I would be glad to 
share thoughts and designs before I embark on my adventure.


Best regards,
Torsten
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Convert codepages back to UTF8

2019-05-28 Thread Sven Barth via fpc-pascal
Alexey Tor.  schrieb am Di., 28. Mai 2019, 14:44:

> Ok, I got it. But I wonder: if my code changes codepage of a "string" to
> e.g. 1250, will all Lazarus string functions work ok with such changed
> string? For ex, will Pos('Петя', s) work?
>

Depends on what you do with the returned value. Lazarus uses UTF-8 by
default, thus the constant would be in UTF-8 as well and Pos() takes two
AnsiString parameters, thus CP_ACP. So the constant is passed along as is
and s is converted to UTF-8. Depending on the encoding of the characters
you might get a different position, thus you should ensure that both of
your strings have the same type (not tested) or you should work simply in
UTF-8 and only convert for input/output purposes.

Regards,
Sven

>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Convert codepages back to UTF8

2019-05-28 Thread Martok
> Although be advised that if your SystemCodePage is not a Unicode 
> codepage, there
> will be data loss due to (sometimes unexpected) internal conversions, 
> regardless
> of the current dynamic string code page.
> 
> 
> As Graeme wrote that shouldn't be the case when converting to UTF-8. And for
> everything else you need to either use string variables with the correct 
> static
> encoding or RawByteString to avoid conversions. 

As I wrote: "if your SystemCodePage is not a Unicode codepage". If it is,
everything mostly works.
And even RawByteString gets unexpected roundtrip-conversions on some operations,
which breaks in funny ways if the SystemCodePage can't represent some characters
in the RBS. I once spent most of a day debugging seemingly random data
corruption until I realized the corrupted bytes were #$81, #$90 etc and the
non-LCL program used CP 1252.

More interesting for Alexey regarding the followup question: the result of any
string operation is in the DefaultSystemCodepage, such as:

  s:= 'abc';
  SetCodePage(RawByteString(s), CP_UTF8, true);
  WriteLn(s, ' ',StringCodePage(s));   // abc 65001
  s:= s + 'd';
  WriteLn(s, ' ',StringCodePage(s));   // abcd 1252


--
Regards,
Martok

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Convert codepages back to UTF8

2019-05-28 Thread Alexey Tor.
Ok, I got it. But I wonder: if my code changes codepage of a "string" to 
e.g. 1250, will all Lazarus string functions work ok with such changed 
string? For ex, will Pos('Петя', s) work?


--
Regards,
Alexey

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Convert codepages back to UTF8

2019-05-28 Thread Sven Barth via fpc-pascal
Martok  schrieb am Mo., 27. Mai 2019, 15:14:

> Am 27.05.2019 um 14:30 schrieb Sven Barth via fpc-pascal:
> > Alexey Tor.  > > schrieb am Mo., 27. Mai 2019, 13:15:
> >
> > LazUtils.LConvEncoding can convert utf8 to codepage (not many
> codepages)
> > and vice versa.
> >
> > FPC 3 can convert utf8 to codepage - via SetCodePage(s, codepage,
> true).
> > But how can FPC convert back - codepage to utf8? Does such way exist?
> >
> >
> > Use CP_UTF8 as code page for SetCodePage or assign the string to a
> UTF8String
> > variable.
>
> Although be advised that if your SystemCodePage is not a Unicode codepage,
> there
> will be data loss due to (sometimes unexpected) internal conversions,
> regardless
> of the current dynamic string code page.
>

As Graeme wrote that shouldn't be the case when converting to UTF-8. And
for everything else you need to either use string variables with the
correct static encoding or RawByteString to avoid conversions.

Regards,
Sven

>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Convert codepages back to UTF8

2019-05-28 Thread Graeme Geldenhuys
On 27/05/2019 2:13 pm, Martok wrote:
> there
> will be data loss due to (sometimes unexpected) internal conversions,

Surely that must be a bug then.  Converting anything to a UTF-x encoding
should be lossless as Unicode is the only standard that supports ALL
languages.

Regards,
  Graeme

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

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal