| View previous topic :: View next topic |
| Author |
Message |
Rolet Voice
Joined: 01 Dec 2008 Posts: 3
|
Posted: Sat Dec 06, 2008 10:41 am Post subject: Mirc Strip Help |
|
|
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: |
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
}
|
|
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Dec 06, 2008 1:35 pm Post subject: |
|
|
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: | | regsub -- {^<([^[:space:]])>} $text {\1} |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
Rolet Voice
Joined: 01 Dec 2008 Posts: 3
|
Posted: Sat Dec 06, 2008 2:29 pm Post subject: |
|
|
| no i want to leave all <> in lol |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Dec 06, 2008 11:20 pm Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|