https://issues.dlang.org/show_bug.cgi?id=18336

Seb <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Add                         |Add
                   |std.algorithm.untilClosingP |std.algorithm.findMatchingP
                   |arens                       |aren

--- Comment #2 from Seb <[email protected]> ---
I just opened this issue because balancedParens is quite limited and could be
generalized.

For the archive. Here's Andrei's response:

> Yah we should have an algorithm findMatchingParen that assumes r.front is the 
> opening paren and advances the range until it's positioned on the 
> corresponding closing paren. An optional rParen can be passed for unusual 
> closing parens.

@Jack:

> I'm wondering how useful something like this would be in real world 

There's the example from dlang.org to parse ddoc strings.
Here's another for finding everything within one HTML tag or all it's enclosing
ones:

"<foo foo=bar/>".findMatchingParen('<', '>').writeln; // foo foo=bar/
"<foo><bar/><foobar><bar/></foobar></foo>".findMatchingParen('<', '>',
2).writeln; // foo><bar/><foobar><bar/></foobar></foo>

https://run.dlang.io/is/ah7wmd

Of course, it would require a better, intuitive API to allow both use cases
nicely.

--

Reply via email to