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: unicode and wide_text_io
  @ 2017-12-28 22:35  7%           ` G.B.
  0 siblings, 0 replies; 8+ results
From: G.B. @ 2017-12-28 22:35 UTC (permalink / raw)


On 28.12.17 16:47, 00120260b@gmail.com wrote:
> Then, how come the norm hasn't made it a bit easier to input/ouput post-latin-1 characters ? Why aren't other norms/characters set/encodings more like special cases ?
> 

Actually, output of non-7-bit, unambiguously encoded text
has been made reasonably easy, I'd say, also defaulting
to what should be expected:

with Ada.Wide_Text_IO.Text_Streams;
with Ada.Strings.UTF_Encoding.Wide_Strings;

procedure UTF is
    --  USD/EUR, i.e. "$/€"
    Ratio : constant Wide_String := "$/" & Wide_Character'Val (16#20AC#);

    use Ada.Wide_Text_Io, Ada.Strings;
begin
    Put_Line (Ratio); --  use defaults, traditional
    String'Write --  stream output, force UTF-8
      (Text_Streams.Stream (Current_Output),
       UTF_Encoding.Wide_Strings.Encode (Ratio));
end UTF;

The above source text uses only 7 bit encoding for post-
latin-1 strings. Only comment text is using a wide_character.

If, instead, source text is encoded by "more" bits, and using
post-latin-1 literals or identifiers, then the compiler
may need to be told. I think that BOMs may be of use, and
in any case, there are compiler switches or some other
vendor specific vocabulary describing source text.


^ permalink raw reply	[relevance 7%]

* Re: Q: Localizing type and package references
  2014-01-06  1:29  0% ` Jeffrey Carter
@ 2014-01-06  8:05  0%   ` Simon Wright
  0 siblings, 0 replies; 8+ results
From: Simon Wright @ 2014-01-06  8:05 UTC (permalink / raw)


Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:

> On 01/05/2014 04:55 PM, b.mcguinness747@gmail.com wrote:
>>
>> --------------------------------------------------------------------------------
>> -- Types - Declarations of data types and related packages
>> --------------------------------------------------------------------------------
>> with Ada.Characters;
>> with Ada.Characters.Wide_Latin_1;
>> with Ada.Strings;
>> with Ada.Strings.Wide_Maps;
>> with Ada.Strings.Wide_Unbounded;
>> with Ada.Wide_Characters;
>> with Ada.Wide_Characters.Handling;
>> with Ada.Wide_Text_IO;
>> with Ada.Wide_Text_IO.Text_Streams;
>>
>> package Types is
>>    package Chars         renames Ada.Characters.Wide_Latin_1;
>>    package Char_Handling renames Ada.Wide_Characters.Handling;
>>    package Char_IO       renames Ada.Wide_Text_IO;
>>    package Char_Maps     renames Ada.Strings.Wide_Maps;
>>    package Char_Streams  renames Ada.Wide_Text_IO.Text_Streams;
>>    package Char_Strings  renames Ada.Strings.Wide_Unbounded;
>>
>>    subtype Char        is Wide_Character;
>>    subtype Char_String is Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
>> end Types;
>>
>> and then tried referencing this from the main program file with:
>>
>> with Types;
>> use  Types;
>>
>> with Char_Strings;
>>
>> but the compiler (Gnat 4.6) complains that there is no file called
>> char_strings.ads.  I am not sure if I have made a simple mistake that
>> can be easily corrected to make this work, or if there is a different
>> approach that I should be trying.
>
> You can only with a library-level package, one not declared in
> anything else. Char_Strings is declared in package types, so it's not
> library level and can't be withed.

So, you can either reclare package Chars etc at library level: for
example, in char_strings.ads,

   with Ada.Strings.Wide_Unbounded;
   package Char_Strings  renames Ada.Strings.Wide_Unbounded;

or you can change your main program file to say

   with Types;
   use Types;
   use Types.Chars;
   use Types.Char_Handling;
   ...

or perhaps

   with Types;
   use Types;
   procedure Main is
      use Chars;
      use Char_Handling;
      ...

^ permalink raw reply	[relevance 0%]

* Re: Q: Localizing type and package references
  2014-01-05 23:55  7% Q: Localizing type and package references b.mcguinness747
@ 2014-01-06  1:29  0% ` Jeffrey Carter
  2014-01-06  8:05  0%   ` Simon Wright
  0 siblings, 1 reply; 8+ results
From: Jeffrey Carter @ 2014-01-06  1:29 UTC (permalink / raw)


On 01/05/2014 04:55 PM, b.mcguinness747@gmail.com wrote:
>
> --------------------------------------------------------------------------------
> -- Types - Declarations of data types and related packages
> --------------------------------------------------------------------------------
> with Ada.Characters;
> with Ada.Characters.Wide_Latin_1;
> with Ada.Strings;
> with Ada.Strings.Wide_Maps;
> with Ada.Strings.Wide_Unbounded;
> with Ada.Wide_Characters;
> with Ada.Wide_Characters.Handling;
> with Ada.Wide_Text_IO;
> with Ada.Wide_Text_IO.Text_Streams;
>
> package Types is
>    package Chars         renames Ada.Characters.Wide_Latin_1;
>    package Char_Handling renames Ada.Wide_Characters.Handling;
>    package Char_IO       renames Ada.Wide_Text_IO;
>    package Char_Maps     renames Ada.Strings.Wide_Maps;
>    package Char_Streams  renames Ada.Wide_Text_IO.Text_Streams;
>    package Char_Strings  renames Ada.Strings.Wide_Unbounded;
>
>    subtype Char        is Wide_Character;
>    subtype Char_String is Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
> end Types;
>
> and then tried referencing this from the main program file with:
>
> with Types;
> use  Types;
>
> with Char_Strings;
>
> but the compiler (Gnat 4.6) complains that there is no file called
> char_strings.ads.  I am not sure if I have made a simple mistake that
> can be easily corrected to make this work, or if there is a different
> approach that I should be trying.

You can only with a library-level package, one not declared in anything else. 
Char_Strings is declared in package types, so it's not library level and can't 
be withed.

-- 
Jeff Carter
"Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!"
Monty Python's Flying Circus
53


^ permalink raw reply	[relevance 0%]

* Q: Localizing type and package references
@ 2014-01-05 23:55  7% b.mcguinness747
  2014-01-06  1:29  0% ` Jeffrey Carter
  0 siblings, 1 reply; 8+ results
From: b.mcguinness747 @ 2014-01-05 23:55 UTC (permalink / raw)


I want to write an Ada program using the Wide_Character type, but I might
want to move to Wide_Wide_Character later on.  So I want to localize all
references to Wide_Character and the associated standard Ada packages to
a single file that I can easily update.  If I was working in C++, I would
use typedefs to create pseudonyms and put these in a header file that I could
#include from various source files.  So I have tried to do something similar
in Ada.  I created the file types.ads:

--------------------------------------------------------------------------------
-- Types - Declarations of data types and related packages
--------------------------------------------------------------------------------
with Ada.Characters;
with Ada.Characters.Wide_Latin_1;
with Ada.Strings;
with Ada.Strings.Wide_Maps;
with Ada.Strings.Wide_Unbounded;
with Ada.Wide_Characters;
with Ada.Wide_Characters.Handling;
with Ada.Wide_Text_IO;
with Ada.Wide_Text_IO.Text_Streams;

package Types is
  package Chars         renames Ada.Characters.Wide_Latin_1;
  package Char_Handling renames Ada.Wide_Characters.Handling;
  package Char_IO       renames Ada.Wide_Text_IO;
  package Char_Maps     renames Ada.Strings.Wide_Maps;
  package Char_Streams  renames Ada.Wide_Text_IO.Text_Streams;
  package Char_Strings  renames Ada.Strings.Wide_Unbounded;

  subtype Char        is Wide_Character;
  subtype Char_String is Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
end Types;


and then tried referencing this from the main program file with:


with Types;
use  Types;

with Char_Strings;


but the compiler (Gnat 4.6) complains that there is no file called
char_strings.ads.  I am not sure if I have made a simple mistake that
can be easily corrected to make this work, or if there is a different
approach that I should be trying.

Help would be appreciated.

Thanks.

--- Brian


^ permalink raw reply	[relevance 7%]

* Re: Why is not Stream_Access defined Ada.Streams ?
  2010-05-07  1:02  7% Why is not Stream_Access defined Ada.Streams ? Yannick Duchêne (Hibou57)
@ 2010-05-07  2:24  0% ` Randy Brukardt
  0 siblings, 0 replies; 8+ results
From: Randy Brukardt @ 2010-05-07  2:24 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

"Yannick Duch�ne (Hibou57)" <yannick_duchene@yahoo.fr> wrote in message 
news:op.vca852lexmjfy8@garhos...
> Hi all and Hi others as well,
>
> My dirty stuff of the day : why is Stream_Access not defined once a time 
> in Ada.Streams and is instead defined elsewhere multiple times, like in 
> Ada.Streams.Stream_IO, Ada.Text_IO.Text_Streams, 
> Ada.Wide_Text_IO.Text_Streams and Ada.Wide_Wide_Text_IO.Text_Streams ?
>
> Isn't it funny design ?

Ada 95 didn't have anonymous access returns, so a named type had to be 
defined. I suspect that there was no intent that it be used for anything 
other than defining the result of these functions -- and there was no intent 
that that result be stored: just directly dereferenced and passed to a 
stream attribute.

If we were writing it today, I'm pretty sure that no named type would be 
used at all. But making a change like that now would be incompatible.

                                Randy.





^ permalink raw reply	[relevance 0%]

* Why is not Stream_Access defined Ada.Streams ?
@ 2010-05-07  1:02  7% Yannick Duchêne (Hibou57)
  2010-05-07  2:24  0% ` Randy Brukardt
  0 siblings, 1 reply; 8+ results
From: Yannick Duchêne (Hibou57) @ 2010-05-07  1:02 UTC (permalink / raw)


Hi all and Hi others as well,

My dirty stuff of the day : why is Stream_Access not defined once a time  
in Ada.Streams and is instead defined elsewhere multiple times, like in  
Ada.Streams.Stream_IO, Ada.Text_IO.Text_Streams,  
Ada.Wide_Text_IO.Text_Streams and Ada.Wide_Wide_Text_IO.Text_Streams ?

Isn't it funny design ?

-- 
No-no, this isn't an oops ...or I hope (TM) - Don't blame me... I'm just  
not lucky



^ permalink raw reply	[relevance 7%]

* Re: implementation question about writing and reading from files
  2001-08-10 14:49  5%     ` Ted Dennison
@ 2001-08-10 15:44  0%       ` Warren W. Gay VE3WWG
  0 siblings, 0 replies; 8+ results
From: Warren W. Gay VE3WWG @ 2001-08-10 15:44 UTC (permalink / raw)


Ted Dennison wrote:
> In article <9kv5rs$6hosn$2@ID-102190.news.dfncis.de>, Francis Crick says...
> >And also, if I want to use a stream for keeping data in memory, how do i
> >that?  How do i instantiate a stream that I can just write to and read from
> >at my leisure?
> 
> The only language-defined streams are in Ada.Streams.Stream_IO,
> Ada.Text_IO.Text_Streams, and Ada.Wide_Text_IO.Text_Streams. I believe they all
> deal with files. If you want to use one to make yourself a buffer, you will have
> to code it yourself by deriving it from Ada.Streams.Root_Stream_Type and
> overriding "Read" and "Write".

If you want a number of examples of streams code, download the AdaVox software
from: http://members.home.net/ve3wwg

I am currently re-vamping AdaVox, because there are a number of design problems
in it, but in the originally released code (see above), you will find
some code that implements a stream buffer. Look for file wc-streams-buffer.ads.

I am sure you can improve upon it, but it will get you started at least.

> 
> >               Also, the data I'm moving is large, and chances are I won't
> >be using it for much else other than writing back to other file streams, so
> >how can i make the reading and writing as fast as possible?  Could I make it
> >read a whole mb in one go as a single unit?
> 
> The easiest way to do that is to unchecked_conversion your data (or better yet,
> a pointer to it) into a Ada.Streams.Stream_Element_Array, then call
> Ada.Streams.Write directly. If you just use the stream attributes, it will
> perform one write for each element, which I've found to be significantly slower
> (even when the target is a memory-based stream).

I think the GNAT implementation is built upon the stdio (C) package, ultimately.
One way to improve performance some, is to increase the buffer size of the 
underlying "file". You'll need to look at the GNAT User Guide to find out how.
You will need to open a C file, and then turn it into an Ada stream.
Maybe someone else can volunteer the details here (I'm too pressed for
time to look it up).

This won't compensate for the procedure(attribute) calls (that Ted referred to), 
but it will make each I/O a larger one.

> A good Ada book should go over the basics of this. Stream use is a complicated
> enough topic that you really ought to have such a resource to learn the basics
> from.

Otherwise, be prepared to look at the streams specs a lot (as I did).
-- 
Warren W. Gay VE3WWG
http://members.home.net/ve3wwg



^ permalink raw reply	[relevance 0%]

* Re: implementation question about writing and reading from files
  @ 2001-08-10 14:49  5%     ` Ted Dennison
  2001-08-10 15:44  0%       ` Warren W. Gay VE3WWG
  0 siblings, 1 reply; 8+ results
From: Ted Dennison @ 2001-08-10 14:49 UTC (permalink / raw)


In article <9kv5rs$6hosn$2@ID-102190.news.dfncis.de>, Francis Crick says...
>And also, if I want to use a stream for keeping data in memory, how do i
>that?  How do i instantiate a stream that I can just write to and read from
>at my leisure? 

The only language-defined streams are in Ada.Streams.Stream_IO,
Ada.Text_IO.Text_Streams, and Ada.Wide_Text_IO.Text_Streams. I believe they all
deal with files. If you want to use one to make yourself a buffer, you will have
to code it yourself by deriving it from Ada.Streams.Root_Stream_Type and
overriding "Read" and "Write". 

>               Also, the data I'm moving is large, and chances are I won't
>be using it for much else other than writing back to other file streams, so
>how can i make the reading and writing as fast as possible?  Could I make it
>read a whole mb in one go as a single unit?

The easiest way to do that is to unchecked_conversion your data (or better yet,
a pointer to it) into a Ada.Streams.Stream_Element_Array, then call
Ada.Streams.Write directly. If you just use the stream attributes, it will
perform one write for each element, which I've found to be significantly slower
(even when the target is a memory-based stream).

A good Ada book should go over the basics of this. Stream use is a complicated
enough topic that you really ought to have such a resource to learn the basics
from.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



^ permalink raw reply	[relevance 5%]

Results 1-8 of 8 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2001-08-05 22:18     implementation question about writing and reading from files Francis Crick
2001-08-05 22:43     ` tmoran
2001-08-09 23:19       ` Francis Crick
2001-08-10 14:49  5%     ` Ted Dennison
2001-08-10 15:44  0%       ` Warren W. Gay VE3WWG
2010-05-07  1:02  7% Why is not Stream_Access defined Ada.Streams ? Yannick Duchêne (Hibou57)
2010-05-07  2:24  0% ` Randy Brukardt
2014-01-05 23:55  7% Q: Localizing type and package references b.mcguinness747
2014-01-06  1:29  0% ` Jeffrey Carter
2014-01-06  8:05  0%   ` Simon Wright
2017-12-27 18:08     unicode and wide_text_io Mehdi Saada
2017-12-28 13:15     ` Mehdi Saada
2017-12-28 14:25       ` Dmitry A. Kazakov
2017-12-28 14:32         ` Simon Wright
2017-12-28 15:28           ` Niklas Holsti
2017-12-28 15:47             ` 00120260b
2017-12-28 22:35  7%           ` G.B.

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