Trivialized problem:

Convert string so that every 'a' between "<bb>...</bb>" is turned into string "bb" and everything between "<U>...</U>" is uppercased.

"aa<bb>aa<U>aa</bb>aa</U>aa" => "aabbbbBBBBAAaa"

Approach problem: I could go first through all </?bb> tags, apply conversions between them and then kill the tags. But that sounds ineffective with longer strings and this is trivialization (sp?) anyways, so I'll just say I want to do this with only one run-through the string, so that the data that's given to processing routine is something like:

"aaaaaaaa", b from offset 2 to 6, U from offset 4 to 8

This where I have a problem; when I apply one conversion, it might invalidate existing offsets inside a string; for example, if I apply the first "b" region, string becomes as following: "aabbbbbbbbaa", causing the 'U' region begin after the 2nd 'b' when it should begin after the 4th 'b'.

I can avoid this sometimes by applying the last conversions first, but if the two regions overlap, this isn't feasible.

You see, with more complicated rules, the real location of 'U' tag becomes quite unpredictable.

What I'd really like would be some sort of magical null-byte that didn't show up on actual representation of string, but hanged around inside the string, moving around like is proper with the character inserts an deletes. And in this spirit I, of course, could add something like '<foo>' to the string temporarily as this hangaround tag, and remove it afterwards, but that's a bit unclean (not to mention dangerous/tricky; what if <foo> already is there?)


Bottom line: if you can think of way to fix the problems with my initial implementation idea or come up with better one for the problem above, one that doesn't iterate through actual tags inside the string many times, I'd be one happy initiate.


In reply to Metatag processing (overlapping regions) by kaatunut

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.