-
Notifications
You must be signed in to change notification settings - Fork 1
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
Substitute parameter for Decode with UTF strings. #78
Comments
Adding a Substitute parameter with a default value to the Decode function is incompatible if it means that Decode no longer causes Encoding_Error. We could repair that by requiring that the default value of Substitute makes Decode work as before -- that is, cause Encoding_Error instead of using the Substitute -- but that would differ from how Substitute parameters work in Ada.Strings.UTF_Encoding, which could be quite confusing. But adding a version of Decode with a Substitute parameter with no default seems ok to me. |
If we want to ensure compatibility with an optional substitute parameter,
it could perhaps default to a raise_expression.
But that's not much different than having two procedures - one without the
parameter that raises, and another with the parameter (not defaulted) that
doesn't.
I don't see any Substitute parameters in Ada.Strings.UTF_Encoding, though.
…On Wed, Feb 14, 2024 at 11:46 AM Niklas Holsti ***@***.***> wrote:
Adding a Substitute parameter with a default value to the Decode function
is incompatible if it means that Decode no longer causes Encoding_Error. We
could repair that by requiring that the default value of Substitute makes
Decode work as before -- that is, cause Encoding_Error instead of using the
Substitute -- but that would differ from how Substitute parameters work in
Ada.Strings.UTF_Encoding, which could be quite confusing. But adding a
version of Decode with a Substitute parameter with no default seems ok to
me.
—
Reply to this email directly, view it on GitHub
<#78 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A4A3SCTEXMFQCM2KY2SFVN3YTTS6ZAVCNFSM6AAAAABB2G4Z2CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBUGIYTGMBYGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***
.com>
|
I think he meant the Substitute parameters in Ada.Characters.Conversions. Maybe not quite as close, but still uncomfortable to have operate differently. |
Yes, apologies for the mis-reference. |
AI22-0102-1 has been created for this issue. |
AI22-0102-1 was approved at ARG meeting #63D. This issue is completed. |
In Ada.Strings.UTF_Encoding.Strings the Decode function
function Decode (Item: UTF_8_String) return String;
causes
Encoding_Error
exception if the string contains a character that is not representable in Latin 1.My proposal is to add a version of Decode with a substitution character, for example:
function Decode (Item: UTF_8_String; Substitute: Character) return String;
or add a Substitute parameter with a default value:
function Decode (Item: UTF_8_String; Substitute: Character := ' ') return String;
A workaround is to use To_String and Decode for Wide_Wide_String, for exemple:
My_String : String := Ada.Characters.Conversions.To_String (Ada.Strings.UTF_Encoding.Wide_Wide_Strings.Decode (My_UTF_String), '#');
A dedicated Decode function would be lighter and simpler by avoiding the need to go back and forth to the Wide_Wide_Strings.
Idem with other Decode forms:
And in Ada.Strings.UTF_Encoding.Wide_Wide_Strings:
The text was updated successfully, but these errors were encountered: