mIRC Home    About    Download    Register    News    Help

Print Thread
Possible Bug in the Remote Identifer $1- #102614 10/11/04 08:21 PM
Joined: Nov 2004
Posts: 5
T
Tiang Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Nov 2004
Posts: 5
I found sth when I try a bit with this code.

When I post a string to a user lets say:

This is a Test of spaces

Then the User become this string with all the spaces, but if he tries to do sth with the text lets say:

on *:text:This is*:?:{
/echo $1-
}

Then there is only one space. So when you type more than one space, the remote Identifer $1- cuts it to one space. Between "is" and "a" there ist only one space, not 8 like at the beginning.

Is this a bug or there are reasons for that?

Sorry for my bad english, hope it is understandable.

Re: Possible Bug in the Remote Identifer $1- #102615 10/11/04 08:44 PM
Joined: Jun 2003
Posts: 5,024
M
Mentality Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Jun 2003
Posts: 5,024
The great space issue!

This is just one of many threads that have reported this as a bug. You can follow the links in that thread and use the search feature to find many more smile

Regards,


Mentality/Chris
Re: Possible Bug in the Remote Identifer $1- #102616 10/11/04 10:03 PM
Joined: Nov 2004
Posts: 5
T
Tiang Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Nov 2004
Posts: 5
Quote:
The great space issue!

This is just one of many threads that have reported this as a bug. You can follow the links in that thread and use the search feature to find many more smile

Regards,


OK reading through the postings I have not find any good solution.

For example sb. say that $1- does hold the un modified line, but wehen i try to $replace $chr(32) with another character it replaces only one space the others are left out. So $1- does not hold the unmodified line. (e.g. //echo $replace($1-,$chr(32),$chr(160)) does not work)

$text for $1-, I don't find this command.

So I have the problem to change the spaces to sth else before thy get strip out.

Can you help me there?

P.S. When everybody knows that the spaces are strip out, why nobody patch this?

Re: Possible Bug in the Remote Identifer $1- #102617 10/11/04 10:56 PM
Joined: Aug 2004
Posts: 147
N
nalAAlan Offline
Vogon poet
Offline
Vogon poet
N
Joined: Aug 2004
Posts: 147
It's how it works...

Re: Possible Bug in the Remote Identifer $1- #102618 10/11/04 11:17 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
For example sb. say that $1- does hold the un modified line

They are wrong. $1- holds the tokenized version of text, so all double (or more) spaces have already been converted to a single space. $rawmsg, on the other hand, contains the raw, unmodified server message. Here's what I use:
Code:
alias text {
  var %a
  !.echo -q $regsub($mid($rawmsg,$calc($pos($rawmsg,$chr(32),3) +2)),/(?<= |^)(?= |$)/g,,%a)
  return %a
}
After you install this alias, you'll be able to use $text instead of $1- in your events. What this alias does is insert bold character (Ctrl+B) pairs between two consecutive spaces. The bold pair itself is invisible but prevents mirc from eating the spaces, so they get displayed.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Possible Bug in the Remote Identifer $1- #102619 11/11/04 01:32 PM
Joined: Nov 2004
Posts: 5
T
Tiang Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Nov 2004
Posts: 5
Quote:
Quote:
For example sb. say that $1- does hold the un modified line

They are wrong. $1- holds the tokenized version of text, so all double (or more) spaces have already been converted to a single space. $rawmsg, on the other hand, contains the raw, unmodified server message. Here's what I use:
Code:
alias text {
  var %a
  !.echo -q $regsub($mid($rawmsg,$calc($pos($rawmsg,$chr(32),3) +2)),/(?<= |^)(?= |$)/g,,%a)
  return %a
}
After you install this alias, you'll be able to use $text instead of $1- in your events. What this alias does is insert bold character (Ctrl+B) pairs between two consecutive spaces. The bold pair itself is invisible but prevents mirc from eating the spaces, so they get displayed.


Thx it realy works great. And the thing with the return was new to me laugh so great help laugh

Cya,
Tiang

Re: Possible Bug in the Remote Identifer $1- #102620 12/11/04 06:55 AM
Joined: Sep 2003
Posts: 149
S
Stealth Offline
Vogon poet
Offline
Vogon poet
S
Joined: Sep 2003
Posts: 149
qwerty, would you mind explaining that regex?


mIRC 6.21 - Win XP Pro (SP2) - 2.4 Ghz - 1 GB Mem
irc.x-tab.org
Re: Possible Bug in the Remote Identifer $1- #102621 12/11/04 02:12 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
(?<=pattern) and (?=pattern) are called assertions. Assertions are different than the classic items like ., [chars] etc in the way that they do not "consume" any characters. To see what I mean, first try this:
//echo -a $regex(abcd,/[a-z](.+)/) - $regml(1)
the output is "1 - bcd". What happened here is that [a-z] matches the letter "a" and consumed it: the rest of the pattern will start matching AFTER the letter "a", because "a" is no longer available to participate in the matching process. It has been consumed by [a-z].

Now try this:
//echo -a $regex(abcd,/(?=[a-z])(.+)/) - $regml(1)
output is now "1 - abcd". That's because (?=[a-z]) did match "a" but did not consume it: it just took a peek at the letter ahead ("a") and made sure that it matches [a-z], hence its name "lookahead assertion". It's a sort of pre-check, to decide if the normal, consuming items can carry on and eat characters. So (.+) starts from "a" (and not from "b", like in the previous example). (?<=[a-z]) is similar, except that it takes a peek behind the current position and is called "lookbehind assertion".

In our case of $text, /(?<= |^)(?= |$)/g matches the position in the string that has a space behind it (or start-of-string) and another space ahead of it (or end-of-string). $regsub() then inserts a ^B pair in that position. Note that using /( |^)( |$)/g wouldn't work correctly. The position between the two spaces would also be found, but the space that's ahead has been consumed, so at the next /g-induced matching round it will no longer play the role of a space behind the current position for ( |^) to find. This means that the expression would fail with 3 consecutive spaces.

It's not easy at all to describe assertions in such a way that their usefulness becomes apparent to the reader. One of the most explanatory docs I've seen on this subject is this, so you may want to take a look at it.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com