Re: [fpc-pascal] string to widestring : what are the difficulties ?

2016-10-09 Thread Michael Van Canneyt



On Sun, 9 Oct 2016, Jonas Maebe wrote:


On 09/10/16 08:50, Sven Barth wrote:

Am 08.10.2016 22:48 schrieb "Ched"
>:

In http://www.freepascal.org/docs-html/ref/refsu14.html#x37-43.2.8
, the stack sized used by a Shortstring is Declared length + 2 . Why not
Declared length + 1 ?


1 Byte length and a zero byte to allow easy conversion to PChar.


That is incorrect. Shortstring stringconstants are stored like that in the 
constant data section so they can be used both for assigning to shortstrings 
and to pchars, but shortstring variables/fields themselves are never 
null-terminated by the compiler/RTL.


So there is in fact an error in the documentation: it should be length + 1.


That has already been corrected.

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


Re: [fpc-pascal] string to widestring : what are the difficulties ?

2016-10-09 Thread Jonas Maebe

On 09/10/16 08:50, Sven Barth wrote:

Am 08.10.2016 22:48 schrieb "Ched"
>:

In http://www.freepascal.org/docs-html/ref/refsu14.html#x37-43.2.8
, the stack sized used by a Shortstring is Declared length + 2 . Why not
Declared length + 1 ?


1 Byte length and a zero byte to allow easy conversion to PChar.


That is incorrect. Shortstring stringconstants are stored like that in 
the constant data section so they can be used both for assigning to 
shortstrings and to pchars, but shortstring variables/fields themselves 
are never null-terminated by the compiler/RTL.


So there is in fact an error in the documentation: it should be length + 1.


Jonas

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


Re: [fpc-pascal] string to widestring : what are the difficulties ?

2016-10-09 Thread Sven Barth
Am 08.10.2016 22:48 schrieb "Ched" <
charles.edouard.des.vastes.vig...@gmail.com>:
> In http://www.freepascal.org/docs-html/ref/refsu14.html#x37-43.2.8 ,
the stack sized used by a Shortstring is Declared length + 2 . Why not
Declared length + 1 ?

1 Byte length and a zero byte to allow easy conversion to PChar.

> Is it easy to change software codes using strings encoded in CP437 to
widestring ? I hope so as widestring has no refcount and so should behave
like string about copy/deep copy.

First WideString as such only exists on Windows for all other platforms
it's am alias of UnicodeString which like AnsiString is reference counted.
Also it's the standard Unicode string type inside the RTL and not
WideString (precisely due to the reference count).
Second the code changes themselves should be neglectable, but you'll need
to check that your files specify the correct codepage or that you store
your files as UTF-8 as otherwise string constants might have unexpected
content.

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