comp.lang.ada
 help / color / mirror / Atom feed
* I need to show extended Ascii codes in GtkAda environment
@ 2019-11-22 13:09 L Dries
  2019-11-22 14:12 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 4+ messages in thread
From: L Dries @ 2019-11-22 13:09 UTC (permalink / raw)


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);
and use it in some other part,
    symbols          : array (1 .. Max_Num, 1 .. 3) of string(1 .. 1) :=
      (("1", "A", "0"),
       ...,
       ("9", "I", "0"),
       (Slash_null, "J", "0"),
       ("A", "K", "0"),
       ...,
       etc.
The GPS program excepts these statements but in the output on the screen 
not only in a GtkAda window but alse in the list with a coming with a 
combo box it is presented as a rectangle with a cross inside. I can give 
another number in the "character'Val(216)" part but the result stays the 
same.
I suppose the problem is within GtkAda but I am not sure abot this.

I am using the highest level of Ada (2012).

How do I solve this problem?
-- 
L. Dries

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: I need to show extended Ascii codes in GtkAda environment
  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   ` Randy Brukardt
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry A. Kazakov @ 2019-11-22 14:12 UTC (permalink / raw)


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);

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: I need to show extended Ascii codes in GtkAda environment
  2019-11-22 14:12 ` Dmitry A. Kazakov
@ 2019-11-22 21:22   ` Randy Brukardt
  2019-11-22 21:36     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 4+ messages in thread
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	[flat|nested] 4+ messages in thread

* Re: I need to show extended Ascii codes in GtkAda environment
  2019-11-22 21:22   ` Randy Brukardt
@ 2019-11-22 21:36     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 4+ messages in thread
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	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-22 21:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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   ` Randy Brukardt
2019-11-22 21:36     ` Dmitry A. Kazakov

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