| View previous topic :: View next topic |
| Author |
Message |
ultralord Master

Joined: 06 Nov 2006 Posts: 255
|
Posted: Sun Feb 08, 2009 7:29 pm Post subject: special char |
|
|
hello.. i have one problem.. i have one tcl script with mysql etc.. when i add one nick in one table and nick have [ ] the problem is when i export the table on php i saw the nick with { } like..
nick[1] and i see it {nick[1]} can i escape the [] and { } from any nick?
i saw here something
http://forum.egghelp.org/viewtopic.php?t=16413&highlight=escape+characters with that command
regsub -all -- {(\\|\[|\]|\&|\{|\}|"|'|\262|\263)} $data {\\\1} data
but i dont know where i must put.. on proc who read the nick or on the tcl anywhere?
thanks a lot.. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sun Feb 08, 2009 8:38 pm Post subject: |
|
|
The presence of {} surrounding strings containing [] usually indicates you're actually dealing with a list.
Think you could post the code in question, would help us see if you really need that regsub, and where to put it should you do... _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
tsukeh Voice
Joined: 20 Jan 2005 Posts: 31
|
|
| Back to top |
|
 |
ultralord Master

Joined: 06 Nov 2006 Posts: 255
|
Posted: Mon Feb 09, 2009 6:11 pm Post subject: |
|
|
i cant unterestand the
proc filt {data} {
regsub -all -- \\\\ $data \\\\\\\\ data
regsub -all -- \\\[ $data \\\\\[ data
regsub -all -- \\\] $data \\\\\] data
regsub -all -- \\\} $data \\\\\} data
regsub -all -- \\\{ $data \\\\\{ data
regsub -all -- \\\" $data \\\\\" data
return $data
}
how it works? $data what var is? i must put there my $nick1 (=nick[1]) ?
thx |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Mon Feb 09, 2009 7:17 pm Post subject: |
|
|
| ultralord wrote: | i cant unterestand the
proc filt {data} {
regsub -all -- \\\\ $data \\\\\\\\ data
regsub -all -- \\\[ $data \\\\\[ data
regsub -all -- \\\] $data \\\\\] data
regsub -all -- \\\} $data \\\\\} data
regsub -all -- \\\{ $data \\\\\{ data
regsub -all -- \\\" $data \\\\\" data
return $data
}
how it works? $data what var is? i must put there my $nick1 (=nick[1]) ?
thx |
That filter is for avoiding double evaluation. That means before you attempt to "inject" commands into the string you run that filter over the string first. This helps protect any tcl special characters already present in the string which might get interpreted as commands. This is useful when you want to use the commands [eval] [subst] or any similar command where double-evaluation can occur. This is the reason you see so many escapes because the string is evaluated the first time, when it is turned into a string
Lets say you use this command:
set text "\[hello\]"
When the string is first evaluated we use single escapes to keep the interpreter from trying to evaluate hello as a command before it can even store anything into $text. When stored as a string these single escapes will be stripped, $text will become simply "[hello]".
But when using [subst] or [eval] over this we have a problem. The hello will be interpreted as a command because it is now being double evaluated. So the above filter can be used to keep the escapes intact when the string is stored into $text. In this way the subsequent [subst]/[eval] will not see hello as a command, but will see the escapes. And once the [subst]/[eval] evaluates the string a second time, those double evaluated escapes will also be stripped. Returning exactly the summary of the embedded commands without stumbling over any other text within.
The interpreter will evaluate three escapes \\\ back into a single escape \. The remaining will remain through each evaluation iteration, and is why you see an odd amount on the right side of the regsub, 5 of them. On the first evaluation the first three will become one. This leaves two left and combined with the one created from the first three, this again becomes three. Eggdrop likes threes.
set text [filt $text]
This is how one would make use of it, but keep in mind if you aren't doing this to avoid double evaluation but instead are using it to correct bad string/list manipulations, this can make your situation even worse. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
ultralord Master

Joined: 06 Nov 2006 Posts: 255
|
Posted: Mon Feb 09, 2009 7:38 pm Post subject: |
|
|
thnx i find my solution set nick1 [ join $nick1 ]
ty. |
|
| Back to top |
|
 |
|