From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4f316de357ae35e9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-31 02:04:56 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!195.27.83.146!news-FFM2.ecrc.net!news.iks-jena.de!lutz From: lutz@iks-jena.de (Lutz Donnerhacke) Newsgroups: comp.lang.ada Subject: Re: FAQ and string functions Date: Wed, 31 Jul 2002 09:04:54 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: <20020730093206.A8550@videoproject.kiev.ua> <4519e058.0207300548.15eeb65c@posting.google.com> <20020731104643.C1083@videoproject.kiev.ua> NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 1028106294 16545 217.17.192.37 (31 Jul 2002 09:04:54 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Wed, 31 Jul 2002 09:04:54 +0000 (UTC) User-Agent: slrn/0.9.6.3 (Linux) Xref: archiver1.google.com comp.lang.ada:27509 Date: 2002-07-31T09:04:54+00:00 List-Id: * Oleg Goodyckov wrote: >Perl we say @list=split(/ /,String) and that's all. Is this Perl's own >especiality? No. It can be realized in Ada. And I say more - without this >Ada will never be convinient language. While for splitting string like >"x=2*3" people will must be to write program enstead split("=","x=2*3"), >people will write in Perl, not Ada. Split is a library function in Perl, not a system call. You can have this library call in Ada, too. Do you consider Perl unusable because MIME::Parser is not in the core language? with Split, Ada.Text_IO, Whole; procedure Test_Split is function Get_Whole_Line is new Whole.Line (Ada.Text_IO.Get_Line); begin loop declare line : constant String := Get_Whole_Line; rang : constant Split.String_Ranges := Split.Split (' ', line); begin Ada.Text_IO.Put_Line ("Words:" & Integer'Image (rang'Length)); for i in rang'Range loop Ada.Text_IO.Put (line (rang (i).first .. rang (i).last)); if i < rang'Last then Ada.Text_IO.Put (", "); end if; end loop; Ada.Text_IO.New_Line; end; end loop; exception when Ada.Text_IO.End_Error => null; end Test_Split; with Ada.Strings.Maps; package Split is pragma Preelaborate (Split); type Ranges is record first : Positive; last : Positive; end record; type String_Ranges is array (Positive range <>) of Ranges; function Split ( Source : String; Set : Ada.Strings.Maps.Character_Set; Test : Ada.Strings.Membership ) return String_Ranges; function Split (Terminator : Character; Source : String) return String_Ranges; end Split; with Ada.Strings.Fixed; package body Split is Null_Ranges : String_Ranges (Positive'First .. Positive'First - 1); function Split (Source : String; Set : Ada.Strings.Maps.Character_Set; Test : Ada.Strings.Membership) return String_Ranges is First, Last : Natural; begin Ada.Strings.Fixed.Find_Token (Source, Set, Test, First, Last); if Last = Natural'First then return Null_Ranges; else return Ranges'(First, Last) & Split (Source (Last + 1 .. Source'Last), Set, Test); end if; end Split; function Split (Terminator : Character; Source : String) return String_Ranges is begin return Split (Source, Ada.Strings.Maps.To_Set (Terminator), Ada.Strings.Outside); end Split; end Split; package Whole is pragma Preelaborate (Whole); buffsize : Positive := 80; generic with procedure Get (buff : out String; last : out Natural); function Line return String; end Whole; package body Whole is function Line return String is buff : String (Positive'First .. Positive'First + buffsize); last : Natural; begin Get (buff, last); if last < buff'Last then return buff (buff'First .. last); else return buff & Line; end if; end Line; end Whole;