mIRC Home    About    Download    Register    News    Help

Print Thread
Parsing characters #225087 25/08/10 03:09 PM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Hi,

For certain reasons, I want to replace certain characters like $, % and " by different characters the moment I receive them, and only convert them back at the very last moment. Now I know how I can script this, but the question is which replacement characters to use.

I'd prefer if $len and similar identifiers don't change due to these characters, but it's ok if they change for characters that are not likely to to appear.

Now I was wondering if characters in the 1-31 range would be suitable for this. Obviously, 2, 3, 15, 22, 29 and 31 are control codes, and thus likely to appear, but what about the others? Though I don't expect line feeds and carriage returns in a single line of text, I'm not touching those just to be sure.

Any other characters in the 1-31 range that can be considered safe/unsafe?


Learning something new every day.
Re: Parsing characters [Re: Thels] #225092 25/08/10 04:37 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
One you could use would be TAB if you're not needing that elsewhere. Not sure about others.

Since I don't talk in channels that use non-English characters, whenever I need to replace text, I will just use a character that isn't going to be used normally. Something like or or or something similar. If I'm replacing something that others may use in channels that use these types of characters, then I typically pick some "random" combination of 3 of those kinds of characters or else just 3 symbols that are unlikely to be used together. This works well, but it does mess up $len/$right/$left/$mid/etc if you need to use those. Of course, that can also be worked around if needed. If those really aren't needed, then this is usually a "safe" way to handle such temporary replacements.


Invision Support
#Invision on irc.irchighway.net
Re: Parsing characters [Re: Thels] #225093 25/08/10 05:01 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Use $crlf. A $crlf *cannot* appear in a single line of text. Problem solved laugh

Re: Parsing characters [Re: Riamus2] #225094 25/08/10 05:06 PM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
I'm currently replacing characters 20, 21, 23, 24, 25, 26, 27, 28 and 30 into a combination of $chr(30) and a number, and the { [ ] " # $ % and } characters by characters 20, 21, 23, 24, 25, 26, 27, 28.

So no characters are getting lost, and $len doesn't change on the presence of { [ ] " # $ % and } characters, but it does on the 20, 21, 23, 24, 25, 26, 27, 28 and 30 characters. Keeping the correct length is not crucial, but I'd like to keep it if possible.


Learning something new every day.
Re: Parsing characters [Re: hixxy] #225095 25/08/10 05:07 PM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: hixxy
Use $crlf. A $crlf *cannot* appear in a single line of text. Problem solved laugh


But those are two characters, right? That beats the purpose of keeping it to a single character for $len purposes.


Learning something new every day.
Re: Parsing characters [Re: Thels] #225099 25/08/10 06:48 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: Thels
and $len doesn't change on the presence of { [ ] " # $ % and } characters


Keep in mind however, that it does change if you have 2 or more of those characters side-by-side.


Invision Support
#Invision on irc.irchighway.net
Re: Parsing characters [Re: Riamus2] #225102 25/08/10 07:14 PM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
Originally Posted By: Riamus2
Originally Posted By: Thels
and $len doesn't change on the presence of { [ ] " # $ % and } characters


Keep in mind however, that it does change if you have 2 or more of those characters side-by-side.


It does? You mean normally, or in this parsed case?

Either way, the size should not chance, since I'm parsing them by different 1 character values.

Those placeholder characters are also parsed themselves just to be sure, and they are parsed in 2 character values, and thus would increase the value of $len.


Learning something new every day.
Re: Parsing characters [Re: Thels] #225105 25/08/10 09:07 PM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
typically you would use $encode( , m) to transform an arbitrary string of text into a (nearly) alphanumeric string that's safe to pass around mIRC without worrying about undesired evaluations. then $decode( , m) can be used to perform the reverse operation

however, all this might be unnecessary. what reason do you have to want to replace all these characters? are you, by any chance, storing lines in a text file then later retrieving them with $read(), only to find that it's being treated as a line of code? if so, you should include the 'n' switch in $read(). there might exist other similarly easy workarounds depending on the nature of your problem


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Parsing characters [Re: jaytea] #225131 26/08/10 09:32 AM
Joined: Aug 2010
Posts: 134
T
Thels Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2010
Posts: 134
I'm not familiar with $encode. Does it retain length? My guess is it wouldn't. But it doesn't really matter as I do want to alter the contents along the way.

I'm not loading or saving. I'm actually displaying the text again right after I'm done with it. Problem is that I'm loading the text into another line that can be customized by the end user. Since I want to allow identifiers to work for the other line and on the text for the message, but keep the message itself as is (save for where outside identifiers affect it), I decided to temporary replace those 8 characters.

Code:
alias -l parse return $replacex($replace($+($chr(32), $1-), $+($chr(32), $chr(32)), $+($chr(32), $chr(160)), $+($chr(160), $chr(32)), $+($chr(160), $chr(160))), $&
$chr(30), $+($chr(30), 9), $chr(20), $+($chr(30), 0), $chr(21), $+($chr(30), 1), $chr(23), $+($chr(30), 3), $chr(24), $+($chr(30), 4), $chr(25), $+($chr(30), 5), $&
$chr(26), $+($chr(30), 6), $chr(27), $+($chr(30), 7), $chr(28), $+($chr(30), 8), $chr(123), $chr(20), $chr(91), $chr(21), $chr(93), $chr(23), $chr(34), $chr(24), $&
$chr(35), $chr(25), $chr(36), $chr(26), $chr(37), $chr(27), $chr(125), $chr(28))

alias -l unparse return $replacex($1-, $chr(28), $chr(125), $chr(27), $chr(37), $chr(26), $chr(36), $chr(25), $chr(35), $chr(24), $chr(34), $chr(23), $chr(93), $&
$chr(21), $chr(91), $chr(20), $chr(123), $+($chr(30), 8), $chr(28), $+($chr(30), 7), $chr(27), $+($chr(30), 6), $chr(26), $+($chr(30), 5), $chr(25), $&
$+($chr(30), 4), $chr(24), $+($chr(30), 3), $chr(23), $+($chr(30), 1), $chr(21), $+($chr(30), 0), $chr(20), $+($chr(30), 9), $chr(30))


The above code seems to work just fine, as far as I could have noticed. I'm just wondering where adding characters in the 20-30 range (skipping 22/29) could cause problems.


Learning something new every day.