From: Gregory Brown Date: 2008-07-31T05:43:17+09:00 Subject: Re: Suggestions for improving a trivial tag parser On Wed, Jul 30, 2008 at 4:35 PM, Robert Dober wrote: > On Wed, Jul 30, 2008 at 8:12 PM, Rolando Abarca wrote: >> On 30-07-2008, at 13:53, Robert Dober wrote: >> >>> What about >>> >>> eles = split( %r{()} ).delete_if{|x| x.empty? } >>> eles.size.one? ? eles.first : eles >> >> I think your regexp is wrong, since it (incorrectly) parses empty tags: > It passed the specs did it not? I did not know what Gregory wanted > exactly, turns out he wanted %r{()} > but he got the message ;). My implementation was tighter than my specs, but I added an extra one to catch this. :) > It would be different if we were treating files, but as the string is > already here we use the memory required by the > specification and nothing more. It does a double pass through the segments rather than a single pass, and I guess that if I had a giant string with a ton of tags I needed to parse, that'd make it less efficient. However, I think it'll be okay for my purposes (PDF inline styling), unless I missed some other concern Rolando had.