comp.lang.ada
 help / color / mirror / Atom feed
* Help with Ada.Strings.Fixed.Find_Token
@ 1999-10-21  0:00 Shawn Barber
  1999-10-21  0:00 ` Ted Dennison
  0 siblings, 1 reply; 2+ messages in thread
From: Shawn Barber @ 1999-10-21  0:00 UTC (permalink / raw)


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 implementation.

Thank you.

Shawn


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!





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

* Re: Help with Ada.Strings.Fixed.Find_Token
  1999-10-21  0:00 Help with Ada.Strings.Fixed.Find_Token Shawn Barber
@ 1999-10-21  0:00 ` Ted Dennison
  0 siblings, 0 replies; 2+ messages in thread
From: Ted Dennison @ 1999-10-21  0:00 UTC (permalink / raw)


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.




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

end of thread, other threads:[~1999-10-21  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-21  0:00 Help with Ada.Strings.Fixed.Find_Token Shawn Barber
1999-10-21  0:00 ` Ted Dennison

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