From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!yy9MKEJN2ULhWGfnfq4v5w.user.gioia.aioe.org.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: XMLAda & unicode symbols Date: Sat, 19 Jun 2021 22:24:45 +0100 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: yy9MKEJN2ULhWGfnfq4v5w.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:2qLhfpcOkHJIYWz16Z0QfQAilig= Xref: reader02.eternal-september.org comp.lang.ada:62250 List-Id: "196...@googlemail.com" <1963bib@googlemail.com> writes: > I'm creating SVG files with XMLAda and I need to have a degree symbol > within some text. > > I have: > procedure Add_Min_Max (Min_Max_Str : String; X_Pos : String; Y_Pos : String) is > Text_Node : DOM.Core.Element; > Text : DOM.Core.Text; > begin > Text_Node := DOM.Core.Documents.Create_Element (LDocument, "text"); > DOM.Core.Elements.Set_Attribute (Text_Node, "x", X_Pos); > DOM.Core.Elements.Set_Attribute (Text_Node, "y", Y_Pos); > DOM.Core.Elements.Set_Attribute (Text_Node, "class", "def-maroon"); > DOM.Core.Elements.Set_Attribute (Text_Node, "text-anchor", "left"); > Text_Node := DOM.Core.Nodes.Append_Child (Root_Node, Text_Node); > Text := DOM.Core.Documents.Create_Text_Node (LDocument, Min_Max_Str); > Text := DOM.Core.Nodes.Append_Child (Text_Node, Text); > end Add_Min_Max; > > and I just pass a string in. The degree symbol is unicode 00B0 and you > would then normally have it as �B0, except if I do, then XMLAda > changes that initial '&' to '&' and so what is then coded is > '&#00B0' and it fails to display properly. > > Nor can I apply Unicode.Names.Latin_1_Supplement.Degree_Sign to the > string, since, well, strict typing... > > To me it seems like XMLAda is being far too eager and is not willing > to just publish what I enter. > > I raised a call on the github repository, but it was closed saying > basically use the unicode name, which fails. Set_Attribute takes a Dom_String, which is a subtype of Unicode.CES.Byte_Sequence, which is a subtype of String. The question is, what encoding? I suspect it's utf-8, so we need to encode Ada.Characters.Latin_1.Degree_Sign in utf-8, & this code using XML/Ada support seems to do the trick: with Ada.Characters.Latin_1; with Ada.Text_IO; with Unicode.CES; with Unicode.Encodings; procedure Conversion is Fifty_Degrees_Latin1 : constant String := "50" & Ada.Characters.Latin_1.Degree_Sign; Fifty_Degrees_UTF8 : constant Unicode.CES.Byte_Sequence := "50" & Unicode.Encodings.Convert ((1 => Ada.Characters.Latin_1.Degree_Sign), From => Unicode.Encodings.Get_By_Name ("iso-8859-15"), To => Unicode.Encodings.Get_By_Name ("utf-8")); begin Ada.Text_IO.Put_Line (Fifty_Degrees_Latin1); Ada.Text_IO.Put_Line (Fifty_Degrees_UTF8); end Conversion; (note that Convert's From and To parameters are the default). On this Mac (Terminal displays utf-8 text) the first line is garbage, the second fine. I'm So Wildly Impressed (maybe "cast down" would be more accurate) by all that subtyping in our wondrously safe language. I also agree with you that suggesting you use a Unicode_Char (Wide_Wide_Character) without saying *how* is less helpful than it could be.