Ada-Rapporteur-Group / User-Community-Input

Ada User Community Input Working Group - Github Mirror Prototype
26 stars 1 forks source link

Substitute parameter for Decode with UTF strings. #78

Closed Blady-Com closed 2 months ago

Blady-Com commented 6 months ago

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:

function Decode (Item : UTF_String; Input_Scheme : Encoding_Scheme) return String;
function Decode (Item : UTF_8_String) return String;
function Decode (Item : UTF_16_Wide_String) return String;

And in Ada.Strings.UTF_Encoding.Wide_Wide_Strings:

function Decode (Item : UTF_String; Input_Scheme : Encoding_Scheme) return Wide_Wide_String;
function Decode (Item : UTF_8_String) return Wide_Wide_String;
function Decode (Item : UTF_16_Wide_String) return Wide_Wide_String;
nholsti commented 5 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.

joshua-c-fletcher commented 5 months ago

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>

ARG-Editor commented 5 months ago

I think he meant the Substitute parameters in Ada.Characters.Conversions. Maybe not quite as close, but still uncomfortable to have operate differently.

nholsti commented 5 months ago

I think he meant the Substitute parameters in Ada.Characters.Conversions.

Yes, apologies for the mis-reference.

ARG-Editor commented 2 months ago

AI22-0102-1 has been created for this issue.

ARG-Editor commented 2 months ago

AI22-0102-1 was approved at ARG meeting #63D. This issue is completed.