xTrivia — File Browser
xTriviav1.0 / xTriviav1.0 / xTriviaByRibellina / xtrivia / bot / Addons / Caratteri.mrc
Caratteri.mrc — 3.16 KB — Download this file
;Start of UTF8 Snippet
;Usage: $utf8(DecimalNumberForSingleUTF8Character)
;Example: //say What the $utf8(191) -- Will output What the ¿
;Result: will display characters beyond the ascii limit of 255.
;Limitations: Valid numbers range is from 1 to 2097151.
;I couldn't find any characters beyond 2097151 that would display in mirc so I didn't script beyond this point.
alias UTF8 {
var %x $base($1,10,2),%y $len(%x)
if ($1 < 161) { return $chr($1) }
elseif (%y < 12) { return $+($shift(11000000,$left(%x,-6)),$shift(10000000,$right(%x,6))) }
elseif (%y < 17) { return $+($shift(11100000,$left(%x,-12)),$shift(10000000,$mid(%x,-12,6)),$shift(10000000,$right(%x,6))) }
elseif (%y < 22) {
return $+($shift(11110000,$left(%x,-18)),$shift(10000000,$mid(%x,$iif(%y < 18,$+(-,%y),-18),6)),$shift(10000000,$mid(%x,-12,6)),$shift(10000000,$right(%x,6)))
}
}
;alias shift -- needed for UTF8 function. Handles the binary bitshift and returns the character conversion.
alias -l shift {
if ($2) { return $chr($base($+($left($1,$+(-,$len($2))),$2),2,10)) }
else { return $chr($base($1,2,10)) }
}
;End UTF8 Snippet
;Start of examples
;Simple menu added to use the demonstration snippets below.
Menu menubar {
-
Caratteri Speciali
..1^Testo:flip $?="Inserisci il testo"
..2^Testo:Octatext $?="Inserisci il testo"
}
;Octatext alias -- Syntax /Octatext text replace with octagon characters.
;Replaces your text with Letters/Numbers in little octagons.
;Limited to upper and lower case letters from a-z and numbers from 1-9
;Demonstrates how you can use the UTF8 alias to make special characters with much shorter code.
alias octatext {
var %octa $regsubex($1-,/([a-z])/g,$utf8($calc($asc($regml(\n)) + 9327)))
%octa = $regsubex(%octa,/([A-Z])/g,$utf8($calc($asc($regml(\n)) + 9333)))
$iif($isid,return,$iif($active ischan,say,echo -a)) $regsubex(%octa,/([1-9])/g,$utf8($calc($asc($regml(\n)) + 10063)))
}
;Flip alias -- Syntax /flip text to turn upside down and backwards.
;Turns your text upside down and backwards.
;Demonstrates the use of $UTF8() to easily display characters from the decimal number.
alias flip {
var %flip, %end $len($1-)
while (%end) {
%flip = $+(%flip,$replace($mid($1-,%end,1),$chr(32),$chr(7)))
dec %end
}
%flip = $replacex(%flip,a,$utf8(592),b,q,c,$utf8(596),d,p,e,$utf8(601),f,$utf8(607),g,$utf8(595),h,$utf8(613),i,$utf8(618),j,$utf8(638),k,$utf8(670),$&
l,$utf8(305),m,$utf8(623),n,u,o,o,p,d,q,b,r,$utf8(633),s,s,t,$utf8(647),u,n,v,$utf8(652),w,$utf8(653),y,$utf8(654),.,$utf8(729),?,$utf8(191),z,z,$chr(7),$chr(32))
$iif($isid,return,$iif($active ischan,say,echo -a)) %flip
}
;;;;;Power Example Below;;;;;
;Usage: $fix&(any string of words/characters that may contain ampersand encoding here)
;Example //say $fix&(This will make a checkmark ✓) <<-- will convert ✓ and replace with a cute little checkmark.
;Limited to characters below 2097152. Does not convert text base encoding like &#amp; etc.
;Very useful when parsing pages at the socket level that use ampersand encoding and special characters or foreign languages.
alias -l fix& { return $regsubex($1-,/\&\#([0-9]{1,});/g,$utf8(\t)) }