Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IIdTextEncoding parameters for AnsiString input on FreePascal 3.0+ #507

Open
rlebeau opened this issue Oct 31, 2023 · 0 comments
Open
Labels
Element: Compiler/IDE Issues related to a particular Compiler and/or IDE Status: Review Needed Issue needs further review to decide next status Type: Enhancement Issue is proposing a new feature/enhancement
Milestone

Comments

@rlebeau
Copy link
Member

rlebeau commented Oct 31, 2023

STRING_IS_ANSI is defined when the string type maps to AnsiString. In this situation, most encoding-aware methods have an extra IIdTextEncoding parameter to specify an AnsiString's input encoding, or desired output encoding.

However, under FreePascal 3.0+, AnsiString is codepage-aware (similar to in Delphi 2009+), so passing in these extra IIdTextEncoding parameters for input strings may be redundant, and even a source for mismatches. When encoding an AnsiString to Unicode and then to charset-encoded bytes, Indy could simply use StringCodePage() to query the AnsiString's codepage, and/or let the RTL just convert AnsiString to UnicodeString without using IIdTextEncoding at all.

Alternatively, simply replace AnsiString+IIdTextEncoding parameter pairs with UnicodeString where appropriate.

Either way, it would be the caller's responsibility to make sure an input AnsiString is assigned the correct codepage before passing it into Indy.

By default, Lazarus uses UTF-8 encoded AnsiString's, so we should let the RTL handle AnsiString->Unicode conversions as much as possible to accommodate this.

However, for the reverse situation, when Indy returns an AnsiString to a caller, the caller should still specify the encoding it wants the AnsiString to be in, so passing in an IIdTextEncoding is still useful in this case. We would just have to make sure SetCodePage() is used appropriately on the output string to match this encoding.

@rlebeau rlebeau added Type: Enhancement Issue is proposing a new feature/enhancement Element: Compiler/IDE Issues related to a particular Compiler and/or IDE Status: Reported Issue has been reported for review labels Oct 31, 2023
@rlebeau rlebeau added this to the Indy 12 milestone Nov 6, 2023
@rlebeau rlebeau added Status: Review Needed Issue needs further review to decide next status and removed Status: Reported Issue has been reported for review labels Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Element: Compiler/IDE Issues related to a particular Compiler and/or IDE Status: Review Needed Issue needs further review to decide next status Type: Enhancement Issue is proposing a new feature/enhancement
Projects
None yet
Development

No branches or pull requests

1 participant