Closed Blady-Com closed 2 months ago
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 https://github.com/Ada-Rapporteur-Group/User-Community-Input/issues/78#issuecomment-1944213084, 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.
I think he meant the Substitute parameters in Ada.Characters.Conversions.
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;
causesEncoding_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: