comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: Help with Ada.Strings.Fixed.Find_Token
Date: 1999/10/21
Date: 1999-10-21T00:00:00+00:00	[thread overview]
Message-ID: <7unp5m$glg$1@nnrp1.deja.com> (raw)
In-Reply-To: 000b8d9b.4395da36@usw-ex0101-004.remarq.com

In article <000b8d9b.4395da36@usw-ex0101-004.remarq.com>,
  Shawn Barber <SbarberNOSbSPAM@snet.net.invalid> wrote:
> Does anyone have an example of Find_Token in use. I'm currently using
> Index to find the start and end position of my search string but I'd
> like to see if Find_Token would be more effective in my

Find_Token (Source, ... Test => Inside) is roughly equivalent to doing
   First := Index (Source, ...);
   Last  := Index (Source(First..Source'last), Test => Outside),

If you were going to do that anyway, it would be useful. But I really
think Find_Token is more trouble than it is worth unless all the
following apply:

   1   You don't care where in the source string the token is found.
   2   The string you want to locate is a coherent set of characters for
which any permutation or combination in any number would be valid.
   3   The character set is also exclusive. By that I mean there is *no*
permutation of combination of any number those characters that could
appear in the search string that you would *not* want matched.

For example, suppose you want to use Find_Token to match an integer,
which you would like to be able to pass straight to Integer'Value
without having to trap Constraint_Error's. If you specify "0123456789"
as the set of characters to match, then you would not match negatives,
and would match parts of identifiers with numbers imbedded in them and
integers with leading 0's (which you would like to be invalid). If you
try to fix the negative problem by specifying "-0123456789", now strings
like "hyper-extend" or "- 5" will report a 1 character match on the
hyphen character.

If your parsing needs are very simple, this isn't a bad approach. If
your needs are more complicated, then I suggest you look into using
either the Gnat.Snobol packages that come with Gnat, or OpenToken (
http://www.telepath.com/dennison/Ted/OpenToken/OpenToken.html ).

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Before you buy.




      reply	other threads:[~1999-10-21  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-21  0:00 Help with Ada.Strings.Fixed.Find_Token Shawn Barber
1999-10-21  0:00 ` Ted Dennison [this message]
replies disabled

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