comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: Ada and Unicode
  @ 2022-04-03 18:04  4%           ` Thomas
  0 siblings, 0 replies; 3+ results
From: Thomas @ 2022-04-03 18:04 UTC (permalink / raw)


In article <s5k0ai$bb5$1@dont-email.me>, "J-P. Rosen" <rosen@adalog.fr> 
wrote:

> Le 19/04/2021 à 15:00, Luke A. Guest a écrit :
> > They're different types and should be incompatible, because, well, they 
> > are. What does Ada have that allows for this that other languages 
> > doesn't? Oh yeah! Types!
> 
> They are not so different. For example, you may read the first line of a 
> file in a string, then discover that it starts with a BOM, and thus 
> decide it is UTF-8.

could you give me an example of sth that you can do yet, and you could 
not do if UTF_8_String was private, please?
(to discover that it starts with a BOM, you must look at it.)


> 
> BTW, the very first version of this AI had different types, but the ARG 
> felt that it would just complicate the interface for the sake of abusive 
> "purity".

could you explain "abusive purity" please?

i guess it is because of ASCII.
i guess a lot of developpers use only ASCII in a lot of situation, and 
they would find annoying to need Ada.Strings.UTF_Encoding.Strings every 
time.

but I think a simple explicit conversion is acceptable, for a not fully 
compatible type which requires some attention.


the best would be to be required to use ASCII_String as intermediate, 
but i don't know how it could be designed at language level:

UTF_8_Var := UTF_8_String (ASCII_String (Latin_1_Var));
Latin_1_Var:= String (ASCII_String (UTF_8_Var));

and this would be forbidden :
UTF_8_Var := UTF_8_String (Latin_1_Var);

this would ensures to raise Constraint_Error when there are somme 
non-ASCII characters.

-- 
RAPID maintainer
http://savannah.nongnu.org/projects/rapid/

^ permalink raw reply	[relevance 4%]

* Re: I need to show extended Ascii codes in GtkAda environment
  2019-11-22 21:22  7%   ` Randy Brukardt
@ 2019-11-22 21:36  5%     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 3+ results
From: Dmitry A. Kazakov @ 2019-11-22 21:36 UTC (permalink / raw)


On 2019-11-22 22:22, Randy Brukardt wrote:

>      Slash_Null : constant String :=
>            Ada.Strings.UTF_Encoding.Strings.Encode (Character'Val(216) & "");

Or using array aggregate

    Ada.Strings.UTF_Encoding.Strings.Encode ((1=>Character'Val(216)));

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 5%]

* Re: I need to show extended Ascii codes in GtkAda environment
  @ 2019-11-22 21:22  7%   ` Randy Brukardt
  2019-11-22 21:36  5%     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 3+ results
From: Randy Brukardt @ 2019-11-22 21:22 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:qr8qbp$15gp$1@gioia.aioe.org...
> On 2019-11-22 14:09, L Dries wrote:
>> In a GtkAda environment I have the need to present some characters or 
>> strings with characters in the Extended character Ascii range for 
>> instance O with slash (216). I create a constant character with
>>
>> Slash_null : constant string(1 .. 1) := "" & character'Val(216);
>
> GTK is UTF-8. You must encode and decode anything that is not ASCII 7-bit. 
> [A pragmatic approach is to ignore the reference manual and treat all 
> strings UTF-8 rather than mandated Latin 1.]
>
> Anyway, assuming you need the LATIN CAPITAL LETTER O WITH STROKE character 
> (code point 216), encoded in UTF-8 it is C3 98. Note, two octets. Thus:
>
>    Slash_Null : constant String :=
>                    Character'Val (16#C3#) & Character'Val (16#98#);
>
> With Strings Edit for Ada you could also write:
>
>    Slash_Null : constant String := Strings_Edit.UTF8.Image (216);

You could of course use Ada.Strings.UTF_Encoding (a standard part of Ada 
2012) to do this as well, by converting the "standard" Latin-1 String to 
UTF-8:

    with Ada.Strings.UTF_Encoding.Strings;
    ...
    Slash_Null : constant String :=
          Ada.Strings.UTF_Encoding.Strings.Encode (Character'Val(216) & "");

Note that concatenating the character with the null string effectively 
creates a string with one character. (You could of course use the literal 
directly if your editor/implementation supports that - tough to do that on 
the Internet, though.)

                                         Randy.





^ permalink raw reply	[relevance 7%]

Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2019-11-22 13:09     I need to show extended Ascii codes in GtkAda environment L Dries
2019-11-22 14:12     ` Dmitry A. Kazakov
2019-11-22 21:22  7%   ` Randy Brukardt
2019-11-22 21:36  5%     ` Dmitry A. Kazakov
2021-04-17 22:03     Ada and Unicode DrPi
2021-04-19  9:08     ` Stephen Leake
2021-04-19 11:56       ` Luke A. Guest
2021-04-19 12:52         ` Dmitry A. Kazakov
2021-04-19 13:00           ` Luke A. Guest
2021-04-19 13:24             ` J-P. Rosen
2022-04-03 18:04  4%           ` Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox