Let’s say we have a tag called test, i.e. [code].
What I’d like to do, is I’d like to only allow up to X other [code] tags inside of every main [code] tag in a string, which means the most inner ones would get removed.
So, for example, if X = 4, the following string:
[code]a[code]b[code]c[code]d[code]e[code]f[code]g[/code][/code][/code][/code][/code][/code][/code]
Would become:
[code]a[code]b[code]c[code]d[code]e[/code][/code][/code][/code][/code]
And the following string:
[code]a[code]b[code]c[code]d[code]TEST[/code][code]e[code]f[code]g[/code][/code][/code][/code][/code][/code][/code]
Would become:
[code]a[code]b[code]c[code]d[code]TEST[/code][code]e[/code][/code][/code][/code][/code]
The goal here is to not have more than a few nested [code] elements inside of a code element, so it doesn’t get too messy.
I’m wondering how to implement this, just trying to think of an algorithm and would appreciate any suggestions.
This is gonna be quite a waste since it would be so easy to add multiple tag support and so on here.
You pretty much have to do fully blown out tree parsing either way.
Note that invalid input is not handled in any way, tags must be properly balanced