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=-0.2 required=3.0 tests=BAYES_00,FREEMAIL_FROM, FROM_STARTS_WITH_NUMS,PDS_FROM_2_EMAILS autolearn=no autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:a0c:bf4b:: with SMTP id b11mr16040109qvj.11.1624209009056; Sun, 20 Jun 2021 10:10:09 -0700 (PDT) X-Received: by 2002:a25:b90:: with SMTP id 138mr15745274ybl.161.1624209008916; Sun, 20 Jun 2021 10:10:08 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 20 Jun 2021 10:10:08 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=2001:8b0:ca:6:0:0:0:fd; posting-account=TiHetgoAAACluCgYkPc8-TWs6dBNgSne NNTP-Posting-Host: 2001:8b0:ca:6:0:0:0:fd References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: XMLAda & unicode symbols From: "196...@googlemail.com" <1963bib@googlemail.com> Injection-Date: Sun, 20 Jun 2021 17:10:09 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:62256 List-Id: On Saturday, 19 June 2021 at 22:24:47 UTC+1, Simon Wright wrote: > "196...@googlemail.com" <196...@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. Asking for the degree sign, was probably a slight mistake. There is Degree_Celsius and also Degree_Fahrenheit for those who have not yet embraced metric. These are the "correct" symbols. Both of these exist in Unicode.Names.Letterlike_Symbols, and probably elsewhere,but trying to shoehorn these in seems impossible. I just wish XMLAda could just accept whatever we throw at it, and if we need to convert it, then let us do so outside of it. Using Text_IO is fine, but not where XMLAda is concerned. B