comp.lang.ada
 help / color / mirror / Atom feed
From: "chris.danx" <spamoff.danx@ntlworld.com>
Subject: An example was Re: Tokens
Date: Mon, 20 May 2002 00:13:12 +0100
Date: 2002-05-20T00:13:12+01:00	[thread overview]
Message-ID: <dkWF8.34770$Iv.4001930@news6-win.server.ntlworld.com> (raw)
In-Reply-To: 3ce81da1$1@news.comindico.com.au


"ProLogic" <ProLogic@prologitech.ods.org> wrote in message
news:3ce81da1$1@news.comindico.com.au...
> Could I you show me a working example of this please? I've read that
entire
> section you have shown me, hmmm

This is a quicky example I wrote in 10mins.  It uses recursion which I think
is clearer in this example, but if it's not clear what is going on I'll
rewrite it with a loop no bother.

If OE mangles it, send me an email (change spamoff to chris)

HTH,
Chris


with ada.strings.fixed;  -- find_token is here;
with ada.strings.maps;   -- character_set is here;
with ada.text_io;

use ada.strings;         -- outside/inside are here;

procedure token_example is

   -- prints all the "words" in a string, where
   -- delims is the set of characters regarded as whitespace.
   --
   procedure what_words (str    : in string;
                         delims : in maps.character_set) is
      first : positive := 1;
      last  : natural := 0;
   begin
      fixed.find_token (str,
                        delims,
                        ada.strings.outside,
                        first,
                        last);

      -- if last = 0 there are no more tokens, so we stop,
      -- otherwise we recur!
      --
      if last > 0 then
         ada.text_io.put (str(first..last) & " & ");

         what_words (str (last + 1..str'last),
                     delims);
      end if;
   end what_words;

   -- a simple character set!
   --
   something_simple : maps.character_set := maps.to_set (" !?,");

begin
   what_words ("My name is bob! And I like skinny dipping parties how about
you?",
               something_simple);
end token_example;








  reply	other threads:[~2002-05-19 23:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-19 15:15 Tokens ProLogic
2002-05-19 16:32 ` Tokens Pascal Obry
2002-05-19 21:23   ` Tokens ProLogic
2002-05-19 21:48   ` Tokens ProLogic
2002-05-19 23:13     ` chris.danx [this message]
2002-05-19 23:30       ` An example was Tokens chris.danx
2002-05-20  3:44         ` David C. Hoos, Sr.
2002-05-20  1:36       ` ProLogic
replies disabled

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