Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Yep, jeffa pointed out a similar example ("2Re: "). That is another good reason to have it as a user setting. It isn't meant to enforce a style upon someone, after all...

The solution would probably be to be able to set which style you prefer for out put, then have the engine look for all those cases and transforming them.

I might take a stab at it later, but for adding that extra complexity, it would have to be both viable to do, and enough people that wants it.

I had seen a few posts with Re^2 and friends, but I didn't think they were that common (plus this is more of a draft and first example). If we can have all the ways, I'm all for it. :)

Personally though, I find the Re^2: style harder to read, even though perhaps more logically correct. :)

Update:

Ok, I took the challenge. Following here is a new version, that handles both types (though not the "2Re:" style, at least not yet). It is about time to start refactoring though, it would seem, as it is getting really hairy. As a demonstration though, it will serve I think.

Now we have some new subs, instead of the old ones, we call the same ones with an added _caret for the "Re^2:" style, and _paranthesis for the "Re(2):" style. This goes for both re_collapse_* and re_add_*. As an added bonus, it will also translate from one type to the chosen one, so you can have it all your style.

Given this approach, and some refactoring, it should be possible to add yet more types. I'm not 100% sure this will hold for every possible case, but the tests I do have seems to indicate it would hold for most stuff.

It also has removed the $& as was pointed out though I din't understand why at first... doh. :) But then, is @- and @+ free from this? I hope so.

Anyhow, here it is - enjoy:

#!/usr/bin/perl -w use strict; use Test; BEGIN { plan tests => 49; } # Collapses sequences of Re: together into one Re(\d): sub re_collapse_parenthesis { return &re_collapse($_[0], "Re(", "): "); } # Collapses sequences of Re: together into one Re^\d: sub re_collapse_caret { return &re_collapse($_[0], "Re^", ": "); } # Collapses sequences together base on $pre and $post: sub re_collapse { my $title = shift; my ($pre, $post) = @_; # Normal 'Re: Re: ' sequences $title =~ s{(Re: ){2,}}{$pre . ($+[0]-$-[0])/4 . $post}ge; # 'Re(\d):' => 'Re^\d:' and vice versa $title =~ s{Re(?:\((\d+)\)|\^(\d+)): }{$pre . ($1||$2) . $post}ge; # Already renumbered: # 'Re: Re(\d+): ' or the Re^\d counterpart while($title =~ s{Re: Re(?:\((\d+)\)|\^(\d+)): } {$pre . (($1||$2) + 1) . $post }ge){}; # 'Re(\d+): Re: ' or the Re^\d counterpart while($title =~ s{Re(?:\((\d+)\)|\^(\d+)): Re: } {$pre . (($1||$2) + 1) . $post }ge){}; # 'Re(\d+): Re(\d+): ' or the Re^\d counterpart while($title =~ s{Re(?:\((\d+)\)|\^(\d+)): Re(?:\((\d+)\)|\^(\d+)): } {$pre . (($1||$2) + ($3||$4)) . $post}ge){}; return $title; } # Adds a new Re: or Re(\d): at the start of a string: sub re_add_parenthesis { return &re_add($_[0], "Re(", "): "); } # Adds a new Re: or Re^\d: at the start of a string: sub re_add_caret { return &re_add($_[0], "Re^", ": "); } # Adds a new Re: etc. based on $pre and $post: sub re_add { my $title = shift; my ($pre, $post) = @_; $title =~ s{^(Re(\((\d+)\)|\^(\d+))?: )?} {($1) ? ($pre . (($3||$4||1) + 1) . $post) : "Re: "}e; return $title; } ########################### # # Tests: # # Testing re_collapse_parenthesis: # Should not change: ok(&re_collapse_parenthesis("(DaP) Re: Foo is not Bar") eq "(DaP) Re: +Foo is not Bar"); ok(&re_collapse_parenthesis("(DaP) Foo is not Bar") eq "(DaP) Foo is n +ot Bar"); ok(&re_collapse_parenthesis("Re(3): (DaP) Re: Foo is not Bar") eq "Re( +3): (DaP) Re: Foo is not Bar"); # Normal Re: sequences: ok(&re_collapse_parenthesis("Re: Re: Foo is not Bar") eq "Re(2): Foo i +s not Bar"); ok(&re_collapse_parenthesis("Re: Re: Re: Foo is not Bar") eq "Re(3): F +oo is not Bar"); ok(&re_collapse_parenthesis("Re: Re: (DaP) Re: Foo is not Bar") eq "Re +(2): (DaP) Re: Foo is not Bar"); ok(&re_collapse_parenthesis("Re: Re: (DaP) Re: Re: Foo is not Bar") eq + "Re(2): (DaP) Re(2): Foo is not Bar"); # Already renumbered: ok(&re_collapse_parenthesis("Re: Re(2): Foo is not Bar") eq "Re(3): Fo +o is not Bar"); ok(&re_collapse_parenthesis("Re(2): Re: Foo is not Bar") eq "Re(3): Fo +o is not Bar"); ok(&re_collapse_parenthesis("Re: Re(2): (DaP) Re: Re(2): Foo is not Ba +r") eq "Re(3): (DaP) Re(3): Foo is not Bar"); ok(&re_collapse_parenthesis("Re(2): Re: Re: Re(2): Foo is not Bar") eq + "Re(6): Foo is not Bar"); ok(&re_collapse_parenthesis("Re: Re(2): (DaP) Re(2): Re: Foo is not Ba +r") eq "Re(3): (DaP) Re(3): Foo is not Bar"); ok(&re_collapse_parenthesis("Re: Re: Re(2): (DaP) Re(2): Re: Re(4): Re +: Foo is not Bar") eq "Re(4): (DaP) Re(8): Foo is not Bar"); # Example from node id 168373: # (Nothing much to do about such). ok(&re_collapse_parenthesis("Re: Re: (Someone) Re: (Someoneelse) Re: ( +Someotherelse) Re: Re: Something") eq "Re(2): (Someone) Re: (Someonee +lse) Re: (Someotherelse) Re(2): Something"); # Testing Re^2 style: ok(&re_collapse_parenthesis("Re: Re^2: Foo is not Bar") eq "Re(3): Foo + is not Bar"); ok(&re_collapse_parenthesis("Re^2: Re: Foo is not Bar") eq "Re(3): Foo + is not Bar"); ok(&re_collapse_parenthesis("Re: Re^2: (DaP) Re: Re^2: Foo is not Bar" +) eq "Re(3): (DaP) Re(3): Foo is not Bar"); ok(&re_collapse_parenthesis("Re^2: Re: Re: Re^2: Foo is not Bar") eq " +Re(6): Foo is not Bar"); ok(&re_collapse_parenthesis("Re: Re^2: (DaP) Re^2: Re: Foo is not Bar" +) eq "Re(3): (DaP) Re(3): Foo is not Bar"); ok(&re_collapse_parenthesis("Re: Re: Re^2: (DaP) Re^2: Re: Re^4: Re: F +oo is not Bar") eq "Re(4): (DaP) Re(8): Foo is not Bar"); ####################### # Testing re_collapse_caret: # Should not change: ok(&re_collapse_caret("(DaP) Re: Foo is not Bar") eq "(DaP) Re: Foo is + not Bar"); ok(&re_collapse_caret("(DaP) Foo is not Bar") eq "(DaP) Foo is not Bar +"); # Normal Re: sequences: ok(&re_collapse_caret("Re(3): (DaP) Re: Foo is not Bar") eq "Re^3: (Da +P) Re: Foo is not Bar"); ok(&re_collapse_caret("Re: Re: Foo is not Bar") eq "Re^2: Foo is not B +ar"); ok(&re_collapse_caret("Re: Re: Re: Foo is not Bar") eq "Re^3: Foo is n +ot Bar"); ok(&re_collapse_caret("Re: Re: (DaP) Re: Foo is not Bar") eq "Re^2: (D +aP) Re: Foo is not Bar"); ok(&re_collapse_caret("Re: Re: (DaP) Re: Re: Foo is not Bar") eq "Re^2 +: (DaP) Re^2: Foo is not Bar"); # Already renumbered: ok(&re_collapse_caret("Re: Re(2): Foo is not Bar") eq "Re^3: Foo is no +t Bar"); ok(&re_collapse_caret("Re(2): Re: Foo is not Bar") eq "Re^3: Foo is no +t Bar"); ok(&re_collapse_caret("Re: Re(2): (DaP) Re: Re(2): Foo is not Bar") eq + "Re^3: (DaP) Re^3: Foo is not Bar"); ok(&re_collapse_caret("Re(2): Re: Re: Re(2): Foo is not Bar") eq "Re^6 +: Foo is not Bar"); ok(&re_collapse_caret("Re: Re(2): (DaP) Re(2): Re: Foo is not Bar") eq + "Re^3: (DaP) Re^3: Foo is not Bar"); ok(&re_collapse_caret("Re: Re: Re(2): (DaP) Re(2): Re: Re(4): Re: Foo +is not Bar") eq "Re^4: (DaP) Re^8: Foo is not Bar"); # Example from node id 168373: # (Nothing much to do about such). ok(&re_collapse_caret("Re: Re: (Someone) Re: (Someoneelse) Re: (Someot +herelse) Re: Re: Something") eq "Re^2: (Someone) Re: (Someoneelse) Re +: (Someotherelse) Re^2: Something"); # Testing Re^2 style: ok(&re_collapse_caret("Re: Re^2: Foo is not Bar") eq "Re^3: Foo is not + Bar"); ok(&re_collapse_caret("Re^2: Re: Foo is not Bar") eq "Re^3: Foo is not + Bar"); ok(&re_collapse_caret("Re: Re^2: (DaP) Re: Re^2: Foo is not Bar") eq " +Re^3: (DaP) Re^3: Foo is not Bar"); ok(&re_collapse_caret("Re^2: Re: Re: Re^2: Foo is not Bar") eq "Re^6: +Foo is not Bar"); ok(&re_collapse_caret("Re: Re^2: (DaP) Re^2: Re: Foo is not Bar") eq " +Re^3: (DaP) Re^3: Foo is not Bar"); ok(&re_collapse_caret("Re: Re: Re^2: (DaP) Re^2: Re: Re^4: Re: Foo is +not Bar") eq "Re^4: (DaP) Re^8: Foo is not Bar"); ####################### # Testing re_add_parenthesis: ok(&re_add_parenthesis("Foo is not Bar") eq "Re: Foo is not Bar"); ok(&re_add_parenthesis("Re: Foo is not Bar") eq "Re(2): Foo is not Bar +"); ok(&re_add_parenthesis("Re(2): Foo is not Bar") eq "Re(3): Foo is not +Bar"); # This one has to be collapsed later, so this is ok: ok(&re_add_parenthesis("Re: Re: Foo is not Bar") eq "Re(2): Re: Foo is + not Bar"); ####################### # Testing re_add_caret: ok(&re_add_caret("Foo is not Bar") eq "Re: Foo is not Bar"); ok(&re_add_caret("Re: Foo is not Bar") eq "Re^2: Foo is not Bar"); ok(&re_add_caret("Re(2): Foo is not Bar") eq "Re^3: Foo is not Bar"); ok(&re_add_caret("Re^2: Foo is not Bar") eq "Re^3: Foo is not Bar"); # This one has to be collapsed later, so this is ok: ok(&re_add_caret("Re: Re: Foo is not Bar") eq "Re^2: Re: Foo is not Ba +r"); #######################


You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.

In reply to Re: Re: Title Re: collapsing revisited by Dog and Pony
in thread Title Re: collapsing revisited by Dog and Pony

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 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? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-08-02 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (19 votes). Check out past polls.

    Notices?