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-30 21:52:35 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: bam@snoopy.apana.org.au (Brian May) Newsgroups: comp.lang.ada Subject: Re: FAQ and string functions Date: 30 Jul 2002 21:52:34 -0700 Organization: http://groups.google.com/ Message-ID: <29e5ffff.0207302052.465a3193@posting.google.com> References: <20020730093206.A8550@videoproject.kiev.ua> <4519e058.0207300548.15eeb65c@posting.google.com> NNTP-Posting-Host: 203.25.148.63 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1028091154 23528 127.0.0.1 (31 Jul 2002 04:52:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 31 Jul 2002 04:52:34 GMT Xref: archiver1.google.com comp.lang.ada:27506 Date: 2002-07-31T04:52:34+00:00 List-Id: > Strings in Ada are particularly tricky for newcommers. One trap is > underuse of perfectly sized string constants. Most strings get their > value once and never need it changed. If that is the case, its fairly > easy to declare the string at the point its value is known, with the > perfect bounds, by using a string constant (possibly inside a > "declare" block). If you do that, it becomes very easy to deal with. I have two questions concerning strings that I can't find answers for in the RM: 1. How do I split a string up into tokens and iterate through the list of tokens (compare with C's strtok function)? 2. Can this ugly looking code be simplified? declare I : Iterator; begin I := Element_Iterator(Class_Element,"parent"); while More(I) loop declare My_Node : Node renames Value(I); Class_Ref : DOM_String renames Get_Attribute(My_Node,"ref"); begin Put_Line(Class_Name(Package_Id,Class_Ref)&"($1,$2,$3)"); end; Next(I); end loop; Free(I); end; where Element_Iterator, More, Value, Next, and Free are my own functions to iterate over elements in a DOM tree in xmlada (without these the code was a real mess). DOM_String is similiar to a string (in fact, I think internally it is defined as a string, but don't quote me on that). Ideally I don't want to have the nested declare block for the sole purpose of saving the result from Get_Attribute, but I am not sure this is possible? eg. I would like to be able to say declare I : Iterator; Class_Ref : DOM_String; begin I := Element_Iterator(Class_Element,"parent"); while More(I) loop Class_Ref := Get_Attribute(Value(I),"ref"); Put_Line(Class_Name(Package_Id,Class_Ref)&"($1,$2,$3)"); Next(I); end loop; Free(I); end; but do it in a legal way. I think this would make the code more readable. Any comments?