Hey Y'all,
After a bit of Googling I've found my answer.
There 2 ways of doing it:
- Without using any unit related to UTF8
- Using LazUTF8
Without using any unit related to UTF8Memo1.Text := Memo1.Text + char(240)+ char(159) + char(152) + char(128);
This will append the
Grinning Face Emoji (😀) to the memo.
But this requires you to translate the code point
U+1F600 to the 4 individual chars.
I've found that it's not that easy when I found the
UnicodeToUTF8Inline function on the
LazUTF8 unit:
function UnicodeToUTF8Inline(CodePoint: cardinal; Buf: PChar): integer;
begin
case CodePoint of
0..$7f:
begin
Result:=1;
Buf[0]:=char(byte(CodePoint));
end;
$80..$7ff:
begin
Result:=2;
Buf[0]:=char(byte($c0 or (CodePoint shr 6)));
Buf[1]:=char(byte($80 or (CodePoint and $3f)));
end;
$800..$ffff:
begin
Result:=3;
Buf[0]:=char(byte($e0 or (CodePoint shr 12)));
Buf[1]:=char(byte((CodePoint shr 6) and $3f) or $80);
Buf[2]:=char(byte(CodePoint and $3f) or $80);
end;
$10000..$10ffff:
begin
Result:=4;
Buf[0]:=char(byte($f0 or (CodePoint shr 18)));
Buf[1]:=char(byte((CodePoint shr 12) and $3f) or $80);
Buf[2]:=char(byte((CodePoint shr 6) and $3f) or $80);
Buf[3]:=char(byte(CodePoint and $3f) or $80);
end;
else
Result:=0;
end;
end;
There is A LOT of bit shifting and ORing in there, LOL!!!
Using LazzUTF8uses
LazUTF8
, StrUtils
;
Memo1.Text := Memo1.Text + UnicodeToUTF8(Hex2Dec('1F600'));
// OR
Memo1.Text := Memo1.Text + UnicodeToUTF8($1F600);
So I guess I have my answer and I'll be doing some more Googling to see if I can find a neat little list of the code points with the names and categories.
If not, I guess I can always scrape
https://emojipedia.org, right? LOL !! 🤣 🤪
Cheers,
Gus