[fpc-pascal] What is the size of AnsiChar
Noah Silva
shiruba at galapagossoftware.com
Fri Nov 9 02:23:02 CET 2012
Hi,
Just to go a step further, even in a UTF16 String, the "Code Element Size"
probably returns 2, but there is still no guarantee that every character
will be handled by one element. For example, all common characters from
European languages, Korean, and Japanese can be handled in 2 bytes in
UTF16, but some uncommon special characters in Japanese might need an
additional 2 bytes. (And for example, the Unicode points for Egyption
hiroglyphic characters require surrogate pairs).
At any rate, I wish more of this stuff would be handled by the base runtime
transparently. For example, the original pascal spec for Copy() says it
will copy X Characters, not X bytes - but FPC copies X bytes. (This means
we have to use different functions to handle f.e. UTF8 strings properly).
Wishing won''t make it come true, but...
Thank you,
Noah Silva
2012/11/5 Jonas Maebe <jonas.maebe at elis.ugent.be>
>
> On 05 Nov 2012, at 11:49, ik wrote:
>
> As I understand, AnsiString and AnsiChar contain the environment type
>> of string (it can be ISO8859x, utf-8 etc...).
>> If that so, how can I know the size (in bytes) of AnsiChar ?
>>
>
> The size of the type "AnsiChar" is always one byte. It is impossible to
> give the size of a generic "character" in a 1-byte string, because in e.g.
> UTF-8 the size depends on the code point. To get the size of a specific
> character, you can use
> widestringmanager.**codepointlengthproc(pchar,**maxlookahead)
>
> "maxlookahead" is the maximum number of bytes that routine is allowed to
> check to find the complete character (e.g. "widestringmanager.**
> codepointlengthproc(@**ansistringvar[3],length(**ansistringvar)-2)"). It
> seems this routine has not yet been implemented for the Windows
> widestringmanager though.
>
>
> Jonas
>
> ______________________________**_________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.**org<fpc-pascal at lists.freepascal.org>
> http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20121109/c870b2c5/attachment.html>
More information about the fpc-pascal
mailing list