Thread Tools Display Modes
07-06-20, 06:01 AM   #1
Clayent
A Murloc Raider
Join Date: Jul 2020
Posts: 7
Question Unicode symbols in a string within quotes

Hi.
How can I put a unicode symbol in a string within quotes? For example, if I have this code in .lua:
['MAIN_TAB'] = "Some text and <unicode symbol of rightwards arrow>"
Then in game I will see this - "Some text and →".

I've found this article - https://stackoverflow.com/questions/...-symbol-in-lua
The solution is: "The UTF-8 encoding of a Unicode character can be inserted in a literal string with the escape sequence \u{XXX} (note the mandatory enclosing brackets), where XXX is a sequence of one or more hexadecimal digits representing the character code point."

I've tried this - ['MAIN_TAB'] = "Some text and \u{2192}" and this - ['MAIN_TAB'] = "Some text and \u2192".
And it is not helpful.

PS: rightwards arrow code is here - https://www.fileformat.info/info/uni...2192/index.htm
  Reply With Quote
07-06-20, 07:03 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
For the german special chars I use this notation

-- ö \195\182 ß \195\159
-- ü \195\188 ä \195\164
-- Ä \195\132
-- ö \195\182
-- Ü \195\156

Not sure how to translate it for your symbol. And I'm not even sure if the symbol is included in the game fonts.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
07-06-20, 07:12 AM   #3
Clayent
A Murloc Raider
Join Date: Jul 2020
Posts: 7
Originally Posted by Rilgamon View Post
And I'm not even sure if the symbol is included in the game fonts.
I forgot about this. Seems font Friz Quadrata TT doesn't have this symbol.
  Reply With Quote
07-06-20, 04:11 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
You can save Lua files in UTF-8. WoW will even ignore the BOM if you wish to add one, which is needed for most Unicode-capable IDEs to recognize that Unicode is being used.

Even though WoW will ignore the BOM in Lua files, this isn't standard feature of Lua. As such, I would avoid using Unicode symbols in function and variable names. However, Lua boasts that its strings are binary-safe, meaning you can put literally anything in them, even embeded null characters. How the host program (WoW in this case) reacts to them in their API functions is a different story.

In summary, UTF-8 symbols are fine in strings and WoW will read them as-is.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-06-20 at 04:51 PM.
  Reply With Quote
07-07-20, 03:23 AM   #5
Clayent
A Murloc Raider
Join Date: Jul 2020
Posts: 7
Originally Posted by SDPhantom View Post
In summary, UTF-8 symbols are fine in strings and WoW will read them as-is.
In this case, could you please add this symbol "→" in any text of any addon and show me a code and an ingame screenshot with result?
  Reply With Quote
07-07-20, 02:48 PM   #6
sezz
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 158
Originally Posted by Clayent View Post
In this case, could you please add this symbol "→" in any text of any addon and show me a code and an ingame screenshot with result?
Not sure what you're using the symbol for, maybe something like this works for you (the problem is that you can't use multiple different fonts at once, so you have to split the text and and anchor the segments manually unless there's a widget I don't know of that that support that):



Lua Code:
  1. local f = CreateFrame("Frame", nil, UIParent);
  2. f:SetPoint("CENTER");
  3. f:SetSize(200, 100);
  4.  
  5. local fs1 = f:CreateFontString(nil, "OVERLAY");
  6. fs1:SetFont([[Fonts\FRIZQT__.TTF]], 12);
  7. fs1:SetPoint("LEFT");
  8. fs1:SetText("This arrow");
  9.  
  10. local fs2 = f:CreateFontString(nil, "OVERLAY");
  11. fs2:SetFont([[Fonts\ARKai_T.TTF]], 12);
  12. fs2:SetPoint("LEFT", fs1, "RIGHT");
  13. fs2:SetText(" → ");
  14.  
  15. local fs3 = f:CreateFontString();
  16. fs3:SetFont([[Fonts\FRIZQT__.TTF]], 12);
  17. fs3:SetPoint("LEFT", fs2, "RIGHT");
  18. fs3:SetText("points right.");

PS: You can also use https://icomoon.io/app/ to generate a font that only contains the symbols you need and use it in your addon.

Edit: Removed LibSharedMedia

Last edited by sezz : 07-10-20 at 07:46 PM.
  Reply With Quote
07-07-20, 03:03 PM   #7
Clayent
A Murloc Raider
Join Date: Jul 2020
Posts: 7
sezz
Don't know how you did this. I use a standard font Friz Quadrata TT (or PT Sans Narrow, or any other) but no one has this symbol - when I paste "→" in chat or in any addon, then "?" shows.
  Reply With Quote
07-10-20, 07:49 PM   #8
sezz
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 158
Originally Posted by Clayent View Post
sezz
Don't know how you did this. I use a standard font Friz Quadrata TT (or PT Sans Narrow, or any other) but no one has this symbol - when I paste "→" in chat or in any addon, then "?" shows.
You can't see it in chat if your chat is not is using a font that includes that character.

Where exactly do you want your addon to show the arrow?
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Unicode symbols in a string within quotes

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off