Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Is there a reason you can't do this yourself?
I'm lazy. And a little bit out of my depth.
You'll need to document this in a little more detail
Update: This problem has been fixed. Finally :-)

The problem is was really simple, it's just a bit difficult to describe precisely and even more difficult to fix properly.

For every expression that matches, the script will would prefix the match with ANSI codes to change the color, then suffix it with another ANSI code to "reset" to the default color. If this overlaps with a previous match on the same line, the ANSI "reset" code will would remove any other color codes that should still have been in effect.

Example 1:
echo "aabbccddee" | em bbccdd red cc blue
would produce
aa[RED]bb[BLUE]cc[RESET]dd[RESET]ee
which is incorrect because the BLUE/RESET resets "dd" which should have been RED.

Example 2:
echo "aabbccddee" | em cc blue bbccdd red
would produce
aabb[BLUE]cc[RESET]ddee
because "bbBLUEccRESETdd" does not match "bbccdd".

I fear the only real solution would be to replace the simple regex substitute with a state machine that uses a color stack to see what color we should reset to. Unfortunately, this means we go from a quick and simple tool to a complicated piece of code that could fail even harder.

Instead of a simple substitution, I now keep an array of the codes I would insert. For each matching rule, I now scan this array to find the proper "reset color code" instead of just inserting a plain ANSI reset. Only when all the matching has finished I apply the codes using substr().

-- Time flies when you don't know what you're doing

In reply to Re^2: "em" - Emphasize text using regular expressions by FloydATC
in thread "em" - Emphasize text using regular expressions by FloydATC

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-19 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found