This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Mirc Strip Help

Help for those learning Tcl or writing their own scripts.
Post Reply
R
Rolet
Voice
Posts: 3
Joined: Mon Dec 01, 2008 8:33 am

Mirc Strip Help

Post by Rolet »

any idea why this will strip <> from text?? trying to get a quote script to work but cant cause if i have <NICK> it strips the lot. but if its <+NICK> its fine

Code: Select all


proc replace {{args ""}} {
	set switches ""
	for {set i 0} {[string match -* [set arg [lindex $args $i]]]} {incr i} {
		if {![regexp -- {^-(nocase|-)$} $arg -> switch]} {
			error "bad switch \"$arg\": must be -nocase, or --"
		}
		if {$switch == "-"} {
			incr i
			break
		}; lappend switches $switch
	}
	set nocase [expr {([lsearch -exact $switches "nocase"] >= "0") ? 1 : 0}]
	set text [lindex $args $i]
	set substitutions [lindex $args [expr $i+1]]
		# Check to see if $substitutions is in list format, if not make it so.
	set substitutions [split $substitutions]
		if {[info tclversion] >= "8.1"} {
		return [expr {($nocase)?
			[string map -nocase $substitutions $text]:
			[string map $substitutions $text]}]
	}
		set re_syntax {([][\\\*\+\?\{\}\,\(\)\:\.\^\$\=\!\|])}
	foreach {a b} $substitutions {
		regsub -all -- $re_syntax $a {\\\1} a
		if {$nocase} {regsub -all -nocase -- $a $text $b text} \
		else {regsub -all -- $a $text $b text}
	}; return $text
}



proc mirc_strip {{args ""}} {
	set switches ""
	if {$switches == ""} {set switches all}
	set arg [lindex $args 0]
	set all [expr {([lsearch -exact $switches all] >= 0) ? 1 : 0}]
	set list [list \002 "" \017 "" \026 "" \037 ""]
	regsub -all -- "\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?" $arg "" arg
	set arg [replace -- $arg [join $list]]
	return $arg
}

proc mq:filter {data} { 
  regsub -all -- "(\002|\017|\026|\037|\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?)"  $data "" data
  set data [mirc_strip $data]
  return $data
}
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

To be honest, I can't see how this piece of code would affect <> in any way.
I must, however, say that it feels somewhat overworked, doing the very same replacements over and over, and using the built-in stripcodes command should yield the very same (if not better) result, although probably much faster.

If you simply wish to remove <> from the first word in the line, I'd suggest using something like this (having the string being stripped in $text) :

Code: Select all

regsub -- {^<([^[:space:]])>} $text {\1}
NML_375
R
Rolet
Voice
Posts: 3
Joined: Mon Dec 01, 2008 8:33 am

Post by Rolet »

no i want to leave all <> in lol
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Well, the pasted code really shouldn't remove them either...
Nevertheless, I still suggest using the stripcodes command to remove control characters such as colours, bold, etc. instead of using the posted script.
NML_375
Post Reply