mIRC Homepage
Posted By: Tat Double color code negation. - 27/03/03 08:37 PM
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.
Posted By: qwerty Re: Double color code negation. - 28/03/03 01:12 PM
I didn't quite get what you want to do. Could you mention some example inputs and the desired results?
Posted By: Aubs Re: Double color code negation. - 28/03/03 01:55 PM
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.

Posted By: Tat Re: Double color code negation. - 28/03/03 08:42 PM
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.
Posted By: qwerty Re: Double color code negation. - 29/03/03 03:56 AM
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
Posted By: Tat Re: Double color code negation. - 29/03/03 04:29 AM
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.
Posted By: Tat Re: Double color code negation. - 29/03/03 07:34 AM
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
}
© mIRC Discussion Forums