Snippets Project Page
Author: maroon
Original: Jaytea
Added: 1y
Updated: Never
mIRC: 7.all
Hits: 282
Downloads: 7
Review: entropy
Size: 2.14KB
1 0
Login to vote.
$chr $asc for full UTF8 range
v1.0
Lets $chr() and $asc() handle numbers larger than 65535, to give you limited support for emojis
Download
JSON
▲ Review
▼ Source
/* { maroon 2022. Hey humans, I stole these from the mIRC forum from where Jaytea posted them. I modified them to preserve $v1 and $v2 in the caller alias, and I fixed a bug where chrU needs to us returnex to prevent the 32 space from returning as $null You use $chrU same as $chr(number) with 2 additional ways. You can use (U+number) where the number is in hex, so $chrU(100) is codepoint 100, and $chrU(U+100) is codepoint 256. Also, while $chr() returns only characters 1-65535, this can return the emojis and other characters above 65535 which scripts see in strings as 2 surrogates, so $chrU(128049) is 1 black cat emoji character, $len($chrU(128049)) = 2 Your mileage may vary for whether your chosen font displays all/none of these. For example, in Win7 there are very few fonts that show the black cat, and some fonts like Dejavu Sans only has limited support outside the 1-65535 range. Segoe UI Symbol seems to be the best in Win7. ascU does the reversal of chrU, by seeing that the codepoint is intended to be the 1st of 2 surrogates If so, and it's followed by something valid from the range for the 2nd surrogate, it differs from $asc() by returning the code point above 65535 instead of the codepoint of the 1st surrogate. //var -s %a $chrU(128049) | echo -a %a is the blackcat emoji at codepoint $ascU(%a) Not all numbers above 65535 are mapped to something, and even some of those are not visible, so you may need to research to find emojis and other symbols you can use: //echo -a $regsubex($str(x,40),/x/g,$chr2($rand(128043,128062))) Enjoy! } */ alias chrU { var %v1 = $v1 , %v2 = $v2 , %chr = $1 if (U+* iswm $1) var %chr $base($mid($1,3),16,10) if (%chr isnum 65536-1114111) { if (%v1 === %v2) !noop | !returnex $chr($calc(55232 + %chr // 1024)) $+ $chr($calc(56320 + %chr % 1024)) } if (%v1 === %v2) !noop !returnex $chr(%chr) } alias ascU { var %v1 = $v1, %v2 = $v2 , %asc = $asc($1) if (%asc isnum 55296-56319) && ($asc($mid($1,2)) isnum 56320-57343) var %asc = $calc(65536 + (%asc - 55296) * 1024 + $v1 % 1024) if (%v1 !=== %v2) noop !returnex %asc }
Changelog:
0
0