mIRC Home    About    Download    Register    News    Help

Topic Options
#17107 - 27/03/03 08:37 PM Double color code negation.
Tat Offline
Babel fish

Registered: 12/01/03
Posts: 87
I am trying to script a quick alias that removes doubled and unneeded color codes out some given text.

Some of the situations such as double bolds double underlines and double reverses are simple to just do a remove on. Double color codes so long as the first color code is blank is also pretty easy.

alias ddc { return $replace($remove($1-,$chr(2) $+ $chr(2)), $chr(3) $+ $chr(3), $chr(3)) }

The problem is I often use quick alias to change the color of specific text and the aliases close the color codes just to have them reopened.

I've tried my hand a bit at picking apart the color codes with regex but it quickly becomes apparent that there are too many combinations to deal with them all very nicely.

B = bold char
/B(\s|[:cntrl:])*B/ replace with B*$regml

Not sure, but has anybody else done something close there to and care to enlighten me on some of the finer points.

Top
#17108 - 28/03/03 01:12 PM Re: Double color code negation.
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
I didn't quite get what you want to do. Could you mention some example inputs and the desired results?
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#17109 - 28/03/03 01:55 PM Re: Double color code negation.
Aubs Offline
Vogon poet

Registered: 10/12/02
Posts: 143
Loc: Sheffield, UK
wouldn't using $strip() do what you are after?

from the help file (/help $strip):

$strip(text,burcmo)
Returns text with all bold, underline, reverse, and color control codes stripped out.

The burcmo parameter is optional, if used, it strips only the specified types of characters.

The m applies the strip settings in the Messages dialog, and the o applies the "only if..." settings in the messages dialog.

_________________________
Aubs.
cool


Top
#17110 - 28/03/03 08:42 PM Re: Double color code negation.
Tat Offline
Babel fish

Registered: 12/01/03
Posts: 87
For the example I shall use B to be chr(2) C to be chr(3) ect.

C03B"Welcome to "CBC12B"My channel!"
C03B"Welcome to "C12"My channel!"

I often use alias like
alias e1 { return C03B $+ $1- $+ CB }
alias e2 { return C12B $+ $1- $+ CB }

$e1(Welcome to ) $+ $e2(My channel!)

But this doesn't actually need to do the closing colors if its just going to start them right back up.

Top
#17111 - 29/03/03 03:56 AM Re: Double color code negation.
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
Try this:
Code:
alias mcodes {
  var %a
  !.echo -q $regsub($1,/([]|(?:\d\d?(?:\x2C\d\d?)?)?)(?=(?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)*?\1)/g,,%a)
  return %a
}

Fex, //echo -a $mcodes($e1(blah) $+ $e2(bleh))

It works for all control codes (not just Ctrl+K)

Edit: fixed a typo in the regex


Edited by qwerty (29/03/03 04:02 AM)
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#17112 - 29/03/03 04:29 AM Re: Double color code negation.
Tat Offline
Babel fish

Registered: 12/01/03
Posts: 87
Wow.
Thanks. That's some killer code.

For a second I thought the background code was bad, I stand corrected. It just took more figured the end background commas delinated more tokens and didn't like it much in my test. Should work great. Very very nice code...

One bug. BB != B BB = $null

$mcodes(BB"Hello") returns B"Hello" ... when it should just return Hello.


Edited by Tat (29/03/03 05:24 AM)

Top
#17113 - 29/03/03 07:34 AM Re: Double color code negation.
Tat Offline
Babel fish

Registered: 12/01/03
Posts: 87
Also... this next alias should work with a much quicker regsub but I am missing something somewhere... I think the match text () are somehow wrong. Alias should remove double colors to the same colors. Excluding the special case of backgrounds. 256 sets would suck.

alias rdc {
var %i = $regex($1,/00[^]*(00)|01[^]*(01)|02[^]*(02)|03[^]*(03)|04[^]*(04)|05[^]*(05)|06[^]*(06)|07[^]*(07)|08[^]*(08)|09[^]*(09)|10[^]*(10)|11[^]*(11)|12[^]*(12)|13[^]*(13)|14[^]*(14)|15[^]*(15)/g), %rt = $1
while (%i >= 1) {
%rt = $left(%rt, $calc($regml(%i).pos - 1)) $+ $right(%rt, $calc(($regml(%i).pos + 2) * -1))
dec %i
}
return %rt
}

Top