Author: maroon
Original: Talon
Added: 7y
Updated: Never
mIRC: used 6.35* & 7.51+
Hits: 2,284
Downloads: 38
Review: entropy
Size: 6.94KB
1
0
Login to vote.
Unescape
v1.0
Unescape by Talon, Munescape alteration by maroon
Use standard escape codes in your script! Plus a few non-standard ones...
It can make your script more readable and eliminate $chr(44)'s and $+
Syntax: $unescape(string)
Example:
//bset -t &v 1 $unescape(\a\b\t\n\v\f\r\e\x2c\u2714) | echo -a $bvar(&v,1-)
Valid codes and their translations:
\a = chr(7) Audible bell
\b = chr(8) Backspace
\t = chr(9) Tab
\r = chr(10) carriage Return aka $cr
\v = chr(11) Vertical tab
\f = chr(12) Formfeed
\n = chr(13) Newline aka $lf
\e = chr(27) Escape
\\ = literal \
\u = unicode16 as 4-digit hex
\x = unicode8 as 2-digit hex
Displays: 7 8 9 10 11 12 13 27 44 226 156 148
Syntax: $munescape(string)
Example:
//echo -a $munescape( \Bbold\Iitalic\Rreverse\Uunderline\O\K4red\K8\M4yellow_on_red\Oreset comma \x2c or \X044 or \X44 or \C44 or \M check \u2714 or \C10004 formfeed= \^L accented-e \X233 $asc($munescape(\^\)) )
Valid Codes and their translations:
Case-sensitive versions of all the above, plus...
\C = followed by 1-5 decimal numbers for chr(1-65535) aka 5-digit decimal form of \uhex
\X = followed by 1-3 decimal numbers for chr( 1-255 ) aka 3-digit decimal form of \uhex
This group is for mIRC color codes, avoids $+ and $chr(44)
\B = chr(2) bold control code from pressing Ctrl+B
\U = chr(31) Underline control code from pressing Ctrl+U
\R = chr(22) reverse colors from pressing Ctrl+R
\K = chr(3) color code from pressing Ctrl+K
\I = chr(29) italics control code from pressing Ctrl+I
\O = chr(15) colors OFF control code from pressing Ctrl+O
\M = chr(44) coMma
\^[a-zA-_] Codes for ASCII 1-31. \^A thru \^Z are chr(1) thru chr(26). \^ followed by [\]^_ are chr(27) thru chr(31)
alias unescape returnex $replacex($regsubex($1,/(\\+)([abtrvfne]|u[0-9a-f]{4}|x[0-9a-f]{2})/gi,$iif($calc($len(\1) % 2),$mid(\1,2) $+ $iif(\2 isin abtrvfne,$replace(\2,a,$chr(7),b,$chr(8),t,$chr(9),r,$cr,v,$chr(11),f,$chr(12),n,$lf,e,$chr(27)),$chr($base($mid(\2,2),16,10))),\1\2)),\\,\) alias munescape returnex $replacex($regsubex($1,/(\\+)([abtrvfneBURKIOM]|(u)([0-9a-fA-F]{4})|(x)([0-9a-fA-F]{2})|(\^)([a-zA-_])|(C)([0-9]{1,5})|(X)([0-9]{1,3}))/g,$iif($calc($len(\1) % 2),$mid(\1,2) $+ $iif(\2 isincs abtrvfneBURKIOM,$replacecs(\2,a,$chr(7),b,$chr(8),t,$chr(9),r,$cr,v,$chr(11),f,$chr(12),n,$lf,e,$chr(27),B,$chr(2),U,$chr(31),R,$chr(22),K,$chr(3),I,$chr(29),O,$chr(15),M,$chr(44)),$replacexcs(\2,u\4,$chr($base(\4,16,10)),x\4,$chr($base(\4,16,10)),^\4,$chr($calc($asc($upper(\4)) -64)),C\4,$chr(\4),X\4,$chr(\4))),\1\2)),\\,\) /* { Unescape by Talon, Munescape alteration by maroon Use standard escape codes in your script! Plus a few non-standard ones... Syntax: $unescape(string) NOTE: Works ok in v6.35 except codepoints above 255 not supported Example: //bset -t &v 1 $unescape(\a\b\t\n\v\f\r\e\x2c\u2714) | echo -a $bvar(&v,1-) Displays: 7 8 9 10 11 12 13 27 44 226 156 148 Syntax: $munescape(string) Example: //echo -a $munescape( \Bbold\Iitalic\Rreverse\Uunderline\O\K4red\K8\M4yellow_on_red\Oreset comma \x2c or \X044 or \X44 or \C44 or \M check \u2714 or \C10004 formfeed= \^L accented-e \X233 $asc($munescape(\^\)) ) I'm posting $unescape with Talon's permission, plus a variant I created which adds extra features at the cost of no longer being case-insensitive. This lets you make strings in mIRC which are styled after standard escape sequences like \r and \n available in many programming languages, plus a few extras. It can eliminate a lot of $+ $chr(number) that make it harder to read your code. If the string parameter contains a backslash followed by specific characters, it's replaced by special items which can be more complicated to include in a string, or which can make your code harder to read. The symbols supported by Unescape are: \a = chr(7) Audible bell \b = chr(8) Backspace \t = chr(9) Tab \r = chr(10) carriage Return aka $cr \v = chr(11) Vertical tab \f = chr(12) Formfeed \n = chr(13) Newline aka $lf \e = chr(27) Escape \\ = literal \ \u = unicode16 as 4-digit hex \x = unicode8 as 2-digit hex Unescape can place many non-alphanumeric characters into the string without using $chr(). Instead of doing colors which can be harder to read: //echo -a $+($chr(3),8,$chr(44),4test) or //echo -a $chr(3) $+ 8, $+ 4test or placing the control codes which can be hard to read except in Fixedsys Excelsior... ... this lets you do yellow-on-red text like: //echo -a $unescape(\x038\x2c4test) \x03 is the color code obtained by pressing Ctrl+K. \x2c is the comma. Since the backslash \ is the symbol which begins all escape codes, you'll need to use \\ if you wish to have a literal backslash in your string, or else use \x5c. If there's not a special code for the character following the backslash, you don't need to escape it. For example, "c:\windows\\fonts\" only needed the double-backslash to avoid \f being the formfeed, but since \w is not a symbol, it did not need to be escaped. In the above $unescape() alias, the codes are case-insensitive, so \R and \r are the same thing. === I've included another version with a few extra features. If you don't need them, use Talon's less complicated alias which would be a little quicker since it doesn't need to do as much. $munescape() supports all the above escape codes, except it is case-sensitive, recognizing the above as lower-case letters ONLY. For example, $unescape(\F) is changed to a formfeed but $munescape(\F) shows those literal two characters instead. In addition, this version supports additional escape codes, including ones specifically relevant only for mIRC: \C = followed by 1-5 decimal numbers for chr(1-65535) aka 5-digit decimal form of \uhex \X = followed by 1-3 decimal numbers for chr( 1-255 ) aka 3-digit decimal form of \uhex This group is for mIRC color codes, avoids $+ and $chr(44) \B = chr(2) bold control code from pressing Ctrl+B \U = chr(31) Underline control code from pressing Ctrl+U \R = chr(22) reverse colors from pressing Ctrl+R \K = chr(3) color code from pressing Ctrl+K \I = chr(29) italics control code from pressing Ctrl+I \O = chr(15) colors OFF control code from pressing Ctrl+O \M = chr(44) coMma \^[a-zA-_] Codes for ASCII 1-31. \^A thru \^Z are chr(1) thru chr(26). \^ followed by [\]^_ are for ASCII 27-31. For example, \^C is Ctrl+C and end-of-file-marker is \^Z This group is case-insensitive, so \^T and \^t are both $chr(20) Note: if you need to follow the \C or \X symbol with numbers, you must pad the symbol to 5 and 3 digits respectively, otherwise it accepts fewer numeric digits. These let you use the decimal value instead of hex. If you know the comma is $chr(44), instead of needing to translate 44 from decimal to hex so you can use it as \x2c, you can instead use \X044. The \C and \X are the same, except \X is intended for the number range 1-255, and accepts a 1-3 digit number to parallel the \x code which accepts a 2-digit hex value. And \C is intended for the number range 1-65535, and accepts a 5-digit number to parallel the \u code that accepts a 4-digit hex value. To keep the alias from being too complicated, \X accepts 000-999 and \C accepts 00000-99999, so be careful about using \X00 or \C98765 which are not valid inputs for $chr() placing those codepoints into your string. It's necessary to left-pad smaller numbers with zeroes only if the code is followed by a number. If the comma is followed by the number 8 number, you need to use \X0448 or \C000448, but if it's followed by a non-numeric, you can use \X44test or \C44test. The \^ lets you have symbols for the characters in the range ASCII 1-31. ASCII 1-26 are matched with the 26 letters of the alphabet \^A through \^Z and ASCII 27-31 are matched with the next 5 characters following Z, which are [\]^_ With the escape codes for mIRC control/color codes, you can make a string much easier to read. Because the Bold code can be \B instead of using $chr(2) or an unfamiliar symbol. In most fonts besides Fixedsys Excelsior, the symbol from pressing Ctrl+B and Ctrl+R and Ctrl+K are very similar, and pressing Ctrl+U or Ctrl+I appear invisible. } */
0
Neat idea! I haven't thoroughly tested this, but its a great idea! Good work marroon & Talon!
