From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fe66ebb10f69d726 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.213.68 with SMTP id nq4mr3726153pbc.2.1330122349297; Fri, 24 Feb 2012 14:25:49 -0800 (PST) Path: h9ni5265pbe.0!nntp.google.com!news1.google.com!postnews.google.com!kh11g2000pbb.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Convert wide_string to string (as the same byte array) Date: Fri, 24 Feb 2012 14:25:43 -0800 (PST) Organization: http://groups.google.com Message-ID: <9b005a0a-989a-4c00-8d8e-6f93fa1cf9e3@kh11g2000pbb.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1330122348 8207 127.0.0.1 (24 Feb 2012 22:25:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 24 Feb 2012 22:25:48 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: kh11g2000pbb.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-02-24T14:25:43-08:00 List-Id: On Feb 24, 2:01=A0pm, Erich wrote: > A newbie question: I need to convert a wide_string to a (platform/ > endian independent) string that represents all the bytes of the > wide_string. How do you do that? Each Wide_Character of the Wide_String will have to map to two Characters of the String. Also, I assume you want things to work so that when your older package does a lexicographic comparison on Strings, it will return the correct result based on how the original Wide_Strings compared. You'll probably want something like this, for each Wide_Character, where S is the String and WS is the Wide_String: S (J) :=3D Character'Val (Wide_Character'Pos (WS (I)) / 256); S (J + 1) :=3D Character'Val (Wide_Character'Pos (WS (I)) mod 256); I'll let you fill in the rest of the details. If you knew you were working with a big-endian machine, I think you could just do an Unchecked_Conversion on the whole string, but you did say endian-independent. -- Adam > Just to make this clear, I'm not looking for a lossy conversion based > on mapping wide_characters to characters, but for a lossless > conversion. > > The reason is that I have an older package that takes a key as string > and need to use it with wide_strings as keys.