Substitute parameter for Decode with UTF strings.
Blady-Com opened this issue · comments
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;
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.
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.