* Question on Ada.Strings.Unbounded.Slice
@ 1996-07-15 0:00 Brian Nettleton @pulsar
0 siblings, 0 replies; 5+ messages in thread
From: Brian Nettleton @pulsar @ 1996-07-15 0:00 UTC (permalink / raw)
Doesn't look like my original posting went through. Here's another try
(my apologies if you receive this twice).
While building David Wheeler's "small" program (part of the Lovelace
tutorial) I came across a problem with Ada.Strings.Unbounded.Slice.
I'm getting Index_error when the High > Length(Source) + 1 (where
High, Length and Source are as defined in spec of Ada.Strings.Unbounded).
Here is a smaller program which displays the problem (i.e. this program
raises Ada.Strings.Index_Error):
with Ada.Strings.Unbounded;
with Ada.Text_Io;
procedure Do_Slice is
package TIO renames Ada.Text_Io;
begin
TIO.Put_Line
( Ada.Strings.Unbounded.Slice
( Source => ASU.To_Unbounded_String( "hello" ),
Low => 1,
High => 7
)
);
end Do_Slice;
RM A.4.4:101 states Slice "propagates Index_Error if Low >
Length(Source) + 1." But the RM is silent on what happens when
High > Length(Source) + 1! Is this an oversight in the RM, or
by silence does the RM mean to imply that Index_Error is only
raised when Low exceeds the bounds of the source? Is it implementation
dependent what happens when High > Length(Source) + 1?
-Brian Nettleton
^ permalink raw reply [flat|nested] 5+ messages in thread
* Question on Ada.Strings.Unbounded.Slice
@ 1996-07-11 0:00 Brian Nettleton @pulsar
1996-07-16 0:00 ` Keith Thompson
0 siblings, 1 reply; 5+ messages in thread
From: Brian Nettleton @pulsar @ 1996-07-11 0:00 UTC (permalink / raw)
While building David Wheeler's "small" program (part of the Lovelace
tutorial) I came across a problem with Ada.Strings.Unbounded.Slice.
I'm getting Index_error when the High > Length(Source) + 1 (where
High, Length and Source are as defined in spec of Ada.Strings.Unbounded).
Here is a smaller program which displays the problem (i.e. this program
raises Ada.Strings.Index_Error):
with Ada.Strings.Unbounded;
with Ada.Text_Io;
procedure Do_Slice is
package TIO renames Ada.Text_Io;
begin
TIO.Put_Line
( Ada.Strings.Unbounded.Slice
( Source => ASU.To_Unbounded_String( "hello" ),
Low => 1,
High => 7
)
);
end Do_Slice;
RM A.4.4:101 states Slice "propagates Index_Error if Low >
Length(Source) + 1." But the RM is silent on what happens when
High > Length(Source) + 1! Is this an oversight in the RM, or
by silence does the RM mean to imply that Index_Error is only
raised when Low exceeds the bounds of the source? Is it implementation
dependent what happens when High > Length(Source) + 1?
-Brian Nettleton
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on Ada.Strings.Unbounded.Slice
1996-07-11 0:00 Brian Nettleton @pulsar
@ 1996-07-16 0:00 ` Keith Thompson
1996-07-21 0:00 ` Robert A Duff
0 siblings, 1 reply; 5+ messages in thread
From: Keith Thompson @ 1996-07-16 0:00 UTC (permalink / raw)
In <DuE7D3.194@thomsoft.com> bn@alsys.com (Brian Nettleton @pulsar) writes:
> While building David Wheeler's "small" program (part of the Lovelace
> tutorial) I came across a problem with Ada.Strings.Unbounded.Slice.
>
> I'm getting Index_error when the High > Length(Source) + 1 (where
> High, Length and Source are as defined in spec of Ada.Strings.Unbounded).
[example deleted]
> RM A.4.4:101 states Slice "propagates Index_Error if Low >
> Length(Source) + 1." But the RM is silent on what happens when
> High > Length(Source) + 1! Is this an oversight in the RM, or
> by silence does the RM mean to imply that Index_Error is only
> raised when Low exceeds the bounds of the source? Is it implementation
> dependent what happens when High > Length(Source) + 1?
According to the current (unapproved) version of AI95-00128, "A call to
Bounded.Slice with High > Length(Source) is equivalent to a call with
High = Length(Source)." In other words, a slice that overlaps the end
of the string is silently truncated.
Personally, I disagree with this; I think the Slice function should
correspond to the predefined slice operation for type String (raising
Index_Error when a slice would raise Constraint_Error). At least two
existing implementations do it this way. I've just submitted a comment
to this effect to the ada-comment mailing list; we'll see what happens.
Incidentally, the problem occurs when High > Length(Source), not just
when High > Length(Source) + 1.
AI95-00128 is one of many commentaries on the Ada 95 standard; they're
available at
<ftp://sw-eng.falls-church.va.us/public/AdaIC/standards/95com/ada-issues>
Note that these commentaries have little or no official standing until
they've gone through an approval process. Someone more directly involved
than I am may wish to comment further on this process.
--
Keith Thompson (The_Other_Keith) kst@thomsoft.com <*>
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
"As the most participatory form of mass speech yet developed, the Internet
deserves the highest protection from government intrusion." -- ACLU v. Reno
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1996-07-25 0:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-15 0:00 Question on Ada.Strings.Unbounded.Slice Brian Nettleton @pulsar
-- strict thread matches above, loose matches on Subject: below --
1996-07-11 0:00 Brian Nettleton @pulsar
1996-07-16 0:00 ` Keith Thompson
1996-07-21 0:00 ` Robert A Duff
1996-07-25 0:00 ` David Wheeler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox