[fpc-pascal] TStringHelper and Utf8String
Thomas Kurz
fpc.2021 at t-net.ruhr
Fri Aug 28 18:42:54 CEST 2026
I've extended the little test program:
```
program Project1;
{$mode objfpc}
{$longstrings on}
uses sysutils;
var S: Utf8string;
begin
S := 'äfoo';
Writeln(PtrUInt(Pointer(S)));
Writeln(PtrUInt(Pointer(String(S))));
Writeln('DefaultSystemCodePage = ', DefaultSystemCodePage);
Writeln('S codepage = ', StringCodePage(S));
Writeln('String(S) codepage = ', StringCodePage(String(S)));
Writeln('Index = ', String(S).IndexOf('f'));
end.
```
Thank you for pointing me to the shortstring/longstring issue. The string pointers are equal and there is no indication for a codepage conversion as part of the cast.
However, the remaining questions are:
1) Is the explicit cast guaranteed to preserve the underlying string and its dynamic codepage without conversion, or is this only an implementation detail?
2) Are there any plans for making the string helpers available with Utf8String and RawByteString, too?
Thanks,
Thomas
----- Original Message -----
From: Bart via fpc-pascal <fpc-pascal at lists.freepascal.org>
To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Sent: Friday, August 28, 2026, 18:08:36
Subject: [fpc-pascal] TStringHelper and Utf8String
On Fri, Aug 28, 2026 at 3:43 PM Bart <bartjunk64 at gmail.com> wrote:
> As expected?
> In the Utf8String 'f' will be at index 3, since the 'ä' will take up 2
> bytes in UTF8-encoding.
Seems I'm wrong.
IndexOf() is zero-based, so 2 is indeed the correct value.
I would have expected/feared that casting to String() would trigger a
codepage conversion to CP_ACP, which is a 1-byte encoding by default
on Windows at least.
--
Bart
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list