Bug 568161 - Add SWT snippet for Unicode usage
Summary: Add SWT snippet for Unicode usage
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.17   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-23 06:32 EDT by Lars Vogel CLA
Modified: 2020-10-29 12:15 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2020-10-23 06:32:01 EDT
AFAICS we have no example how to use Unicode in SWT. IIRC we also support this in SWT.

Can we add one? For example, I struggling to use the close symbol from https://www.fileformat.info/info/unicode/char/274c/index.htm on a SWT label and an example would be helpful.
Comment 1 Lars Vogel CLA 2020-10-23 06:37:49 EDT
Btw. I know that I can paste unicode charactors into source code but did not find how to get from Unicode U+274C to the actual Charakter.
Label label = new Label....
label.setText("❌" + "⛲");
Comment 2 Lars Vogel CLA 2020-10-28 05:13:47 EDT
Christoph, can you help here?
Comment 3 Christoph Laeubrich CLA 2020-10-28 05:48:47 EDT
This is not SWT specific, for this particular symbol one can simply create a String the following way:

> System.out.println("\u274C");

Of course also

> Label label = new Label....
> label.setText("\u274C"); 

would work.

Just take into consideration java only supports "lower" Unicode to be encoded directly, for example emoji symbols[1] requires "higher" Unicode, the are a little bit unconvenient to use, but you can simply use the UTF-8 bytes:

> System.out.println(new String(new byte[]{(byte)0xF0, (byte)0x9F, (byte)0x98, (byte)0x81}, StandardCharsets.UTF_8));


[1] https://apps.timwhitlock.info/emoji/tables/unicode
Comment 4 Christoph Laeubrich CLA 2020-10-28 05:55:29 EDT
BTW: the link you provided also has this in the table if you scroll down a bit:

> C/C++/Java source code 	"\u274C"

😉
Comment 5 Lars Vogel CLA 2020-10-29 12:15:25 EDT
Thanks a lot, Christoph. Very helpful!