Bart via fpc-devel <[email protected]> schrieb am So., 6. Apr.
2025, 23:19:
> Hi,
>
> Is this a known issue?
> ===
> program z;
>
> {$longstrings on}
> {$zerobasedstrings on}
>
> var
> S, T: string;
> begin
> S := 'ABC';
> write('S[0] = "',S[0],'"');
> if (S[0] <> 'A') then writeln(', FAIL: expected: A') else writeln('
> [Ok]');
> write('S[1] = "',S[1],'"');
> if (S[1] <> 'B') then writeln(', FAIL: expected: A') else writeln('
> [Ok]');
> write('S[2] = "',S[2],'"');
> if (S[2] <> 'C') then writeln(', FAIL: expected: A') else writeln('
> [Ok]');
> T := Copy(S,0,1);
> write('Copy(S,0,1) = "',T,'"');
> if (T <> 'A') then writeln(', FAIL: expected: A') else writeln(' [Ok]');
> T := Copy(S,1,1);
> write('Copy(S,1,1) = "',T,'"');
> if (T <> 'B') then writeln(', FAIL: expected: B') else writeln(' [Ok]');
> end.
> ===
>
> Outputs:
> S[0] = "A" [Ok]
> S[1] = "B" [Ok]
> S[2] = "C" [Ok]
> Copy(S,0,1) = "A" [Ok]
> Copy(S,1,1) = "A", FAIL: expected: B
>
>
> (I played a little with this because Copy() accepts Index < 1 for
> "normal" AnsiStrings, and in Lazarus Utf8Copy() does not, so I wanted
> to see how his behaved with zerobasedstrings on.
>
Please report a bug.
B.t.w. Is there an associate short option for this, as currently you
> cannot check {$IFOPT zerobasedstrings+} nor any other longoptions
> IIRC.)
>
No there's not.
Also it would be best to simply document as UTF8Copy working 1-based
because you can't detect from the callee-side whether it had been enabled
on the caller-side (especially if they're from different units).
Regards,
Sven
>
_______________________________________________
fpc-devel maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel