comp.lang.ada
 help / color / mirror / Atom feed
* Wide_Text_IO: bad data in text file
@ 2002-10-24 20:32 Adam Beneschan
  0 siblings, 0 replies; 6+ messages in thread
From: Adam Beneschan @ 2002-10-24 20:32 UTC (permalink / raw)


Question:

When Wide_Text_IO.Get is used to read a character or string from the
text file, and the file contains a sequence of bits that cannot be
interpreted as a character or string, does the language specify what
exception, if any, should be raised?  Or is it
implementation-dependent?

This isn't really a problem with Text_IO.  For Wide_Text_IO, though,
it's likely that the file will be read using a specific encoding
scheme, such as UTF-8; and it is possible for the file to contain
8-bit bytes that do not represent legal encodings in UTF-8 (or other
encoding scheme).

The RM doesn't specifically address this issue, as far as I can tell. 
Data_Error seems to be intended for cases where characters can be read
from the file but they're not in the proper syntax for an integer
(when using an instance of Integer_IO), or a float, or whatever.  The
closest thing I could find was A.13(10), which says "Use_Error is
propagated if an operation is attempted that is not possible for
reasons that depend on characteristics of the external file".  When I
tried a test using GNAT, it raised Constraint_Error, which seems
counterintuitive.

Comments?

				-- thanks, Adam



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

* Re: Wide_Text_IO: bad data in text file
@ 2002-10-25  4:56 Grein, Christoph
  2002-10-25 11:48 ` Jean-Pierre Rosen
  2002-10-25 15:22 ` Adam Beneschan
  0 siblings, 2 replies; 6+ messages in thread
From: Grein, Christoph @ 2002-10-25  4:56 UTC (permalink / raw)


> The RM doesn't specifically address this issue, as far as I can tell. 
> Data_Error seems to be intended for cases where characters can be read
> from the file but they're not in the proper syntax for an integer
> (when using an instance of Integer_IO), or a float, or whatever.  The
> closest thing I could find was A.13(10), which says "Use_Error is
> propagated if an operation is attempted that is not possible for
> reasons that depend on characteristics of the external file".  When I
> tried a test using GNAT, it raised Constraint_Error, which seems
> counterintuitive.

Exactly when did Gnat raise Constraint_Error? At the Get? Or later when you use the value 
read?

My interpretation of the RM is that Data_Error should be raised, however it need 
not be raised if this would be too much of a burden (cannot be easily done). If 
Data_Error is not raised, you have invalid data.

The 'Valid attribute can be used to insure that the data read really is valid 
(i.e. has a legal interpretation). This attribute is there for just this 
purpose.



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

* Re: Wide_Text_IO: bad data in text file
  2002-10-25  4:56 Wide_Text_IO: bad data in text file Grein, Christoph
@ 2002-10-25 11:48 ` Jean-Pierre Rosen
  2002-10-25 15:22 ` Adam Beneschan
  1 sibling, 0 replies; 6+ messages in thread
From: Jean-Pierre Rosen @ 2002-10-25 11:48 UTC (permalink / raw)


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


"Grein, Christoph" <christoph.grein@eurocopter.com> a �crit dans le message
news: mailman.1035522182.23022.comp.lang.ada@ada.eu.org...
>
> Exactly when did Gnat raise Constraint_Error? At the Get? Or later when
you use the value
> read?
>
Gnat raises Constraint_Error at the Get (this is documented in the
top-secret documentation).
By default, Gnat uses bracket encoding, and therefore you cannot read plain
text with Wide_Text_IO if the file happens to contain square brackets -
quite annoying actually.

--
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





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

* Re: Wide_Text_IO: bad data in text file
  2002-10-25  4:56 Wide_Text_IO: bad data in text file Grein, Christoph
  2002-10-25 11:48 ` Jean-Pierre Rosen
@ 2002-10-25 15:22 ` Adam Beneschan
  2002-10-25 17:22   ` Frank J. Lhota
  1 sibling, 1 reply; 6+ messages in thread
From: Adam Beneschan @ 2002-10-25 15:22 UTC (permalink / raw)


"Grein, Christoph" <christoph.grein@eurocopter.com> wrote in message news:<mailman.1035522182.23022.comp.lang.ada@ada.eu.org>...
> > The RM doesn't specifically address this issue, as far as I can tell. 
> > Data_Error seems to be intended for cases where characters can be read
> > from the file but they're not in the proper syntax for an integer
> > (when using an instance of Integer_IO), or a float, or whatever.  The
> > closest thing I could find was A.13(10), which says "Use_Error is
> > propagated if an operation is attempted that is not possible for
> > reasons that depend on characteristics of the external file".  When I
> > tried a test using GNAT, it raised Constraint_Error, which seems
> > counterintuitive.
> 
> Exactly when did Gnat raise Constraint_Error? At the Get? Or later when you
> use the value read?

The exception was raised by Get.

> My interpretation of the RM is that Data_Error should be raised, however it
> need not be raised if this would be too much of a burden (cannot be easily
> done). If Data_Error is not raised, you have invalid data.
> 
> The 'Valid attribute can be used to insure that the data read really is valid 
> (i.e. has a legal interpretation). This attribute is there for just this 
> purpose.

Sorry, this doesn't make sense to me.  Unless I'm missing something, I
don't think it's possible for Wide_Character'Value ever to return
False in GNAT or in  most other implementations.  This is because a
Wide_Character would be represented in memory by a 16-bit object, and
all 2**16 possible 16-bit values are valid representations for a
Wide_Character.  The issue here isn't whether an Ada object (which
would be in memory or registers) is valid but whether a bit sequence
in the *file* is valid.  (In UTF-8, e.g., it takes 8 to 24 bits to
represent a Wide_Character.)  I don't see how 'Valid can be used to
test that.

				-- Adam



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

* Re: Wide_Text_IO: bad data in text file
  2002-10-25 15:22 ` Adam Beneschan
@ 2002-10-25 17:22   ` Frank J. Lhota
  2002-10-26  1:21     ` Adam Beneschan
  0 siblings, 1 reply; 6+ messages in thread
From: Frank J. Lhota @ 2002-10-25 17:22 UTC (permalink / raw)


"Adam Beneschan" <adam@irvine.com> wrote in message
news:b4682ab7.0210250722.41ac473a@posting.google.com...
> Sorry, this doesn't make sense to me.  Unless I'm missing something, I
> don't think it's possible for Wide_Character'Value ever to return
> False in GNAT or in  most other implementations.

I think you meant to say that it is not possible for Wide_Character'Valid to
return False. I can guarantee that Wide_Character'Value does not return
False, since Wide_Character'Value returns Wide_Character, not Boolean.





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

* Re: Wide_Text_IO: bad data in text file
  2002-10-25 17:22   ` Frank J. Lhota
@ 2002-10-26  1:21     ` Adam Beneschan
  0 siblings, 0 replies; 6+ messages in thread
From: Adam Beneschan @ 2002-10-26  1:21 UTC (permalink / raw)


"Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> wrote in message news:<F5fu9.2322$IU6.1034@nwrddc03.gnilink.net>...
> "Adam Beneschan" <adam@irvine.com> wrote in message
> news:b4682ab7.0210250722.41ac473a@posting.google.com...
> > Sorry, this doesn't make sense to me.  Unless I'm missing something, I
> > don't think it's possible for Wide_Character'Value ever to return
> > False in GNAT or in  most other implementations.
> 
> I think you meant to say that it is not possible for Wide_Character'Valid to
> return False. I can guarantee that Wide_Character'Value does not return
> False, since Wide_Character'Value returns Wide_Character, not Boolean.

Yep.  Typographically'Valid ("Wide_Character'Value") = False.

				-- Adam



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

end of thread, other threads:[~2002-10-26  1:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-25  4:56 Wide_Text_IO: bad data in text file Grein, Christoph
2002-10-25 11:48 ` Jean-Pierre Rosen
2002-10-25 15:22 ` Adam Beneschan
2002-10-25 17:22   ` Frank J. Lhota
2002-10-26  1:21     ` Adam Beneschan
  -- strict thread matches above, loose matches on Subject: below --
2002-10-24 20:32 Adam Beneschan

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