Thread Tools Display Modes
01-04-13, 07:02 AM   #1
Anja
A Fallenroot Satyr
 
Anja's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 27
special letters

Code:
dkp = {
["Fr\195\170em\195\162n"] = 56.00
}
How can i get This value


dkp.playername doenst work with special letters, can i first convert the playername string to this \170\162 Stuff? to get the right array key?

something like...

Code:
s = Frêemân
local function convert(s)


 return s -- like Fr\195\170em\195\162n
end

Last edited by Anja : 01-04-13 at 07:09 AM.
  Reply With Quote
01-04-13, 09:13 AM   #2
humfras
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 131
dkp.blabla is the same as dkp["blabla"].

For a string value, use (e.g.)

local s = "blabla"
local val = dkp[s]
__________________
Author of VuhDo CursorCastBar OptiTaunt Poisoner RaidMobMarker
  Reply With Quote
01-04-13, 09:40 AM   #3
Anja
A Fallenroot Satyr
 
Anja's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 27
but when the string value is with special character like é or â then i didnt find the array key because of this \015\102 in it, how can i convert the á into \016 ?! to match the key in the array?!
  Reply With Quote
01-04-13, 10:19 AM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
If we're talking about an in-game addon (.lua) then making sure you save your file as utf8 should suffice for saving and looking up keys without escaping characters.

That is save as [blâblâ] and look it up the same way.

If you have a web interface parsing saved variables, or you need to copy paste from in-game to a web site or some other interaction of the kind, provide more information about what exactly you're trying to accomplish and in what environment

Last edited by Dridzt : 01-04-13 at 10:22 AM.
  Reply With Quote
01-04-13, 10:48 AM   #5
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 308
Yeah the question here is why your string contains utf8 format instead of plain text. As Driz asked, are you using an external dkp extracting addon or something?

Saving as...
Code:
dkp = {
["Frêemân"] = 56.00
}
and then grabbing the data by..
Code:
dkp["Frêemân"]
If it's a must to where you have to use utf8 then you would want to create a table with all the special characters in it with their utf format and then making a replace/convert function to use that table.
__________________
AddOns: Tim @ WoWInterface
Characters: Mage, Priest, Devoker, Pally
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
01-04-13, 10:54 AM   #6
Anja
A Fallenroot Satyr
 
Anja's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 27
yepp the data format ist only like

["B\195\162be"] or
["Dw\195\161yna"] = {
["DKP"] = 100.00
}

the data comes from http://absence-gilde.com/eqdkp/getdkp.php eqdkp
the old addon "GetDKP" doesnt work, so i codet my own little "whisper to get dkp" addon.

it works fine, (with my very bad code *g*) but the utf8 problem let it only work for normal character names.

Code:
SLASH_DKP1 = "/dkp"
SlashCmdList["DKP"] = function(msg, editBox)
    -- change the text on the editBox.
    print("Du hast "..gdkp.players.Ikuria.DKP.. "DKP")
end

local function filter(self, event, msg, sender)
	split = string.match(msg, " (%w+)")
	if (split) then
	firstchar = split:sub(1,1)
	firstchar = firstchar:upper()
	split = split:sub(2)
	split = firstchar .. split
	end
	if (self:GetName() == "ChatFrame1") then
		if (gdkp.players[split]) then
			SendChatMessage(split.." hat "..gdkp.players[split].DKP.. " DKP aus ".. gdkp.players[split].rcount .. " gespielten Raids.", "WHISPER", nil, sender)
			return true
		else
			if (msg == "!dkp" or msg == "?dkp") then
				if (gdkp.players[sender]) then
					SendChatMessage("Du hast "..gdkp.players[sender].DKP.. " DKP aus ".. gdkp.players[sender].rcount .. " gespielten Raids.", "WHISPER", nil, sender)
					return true
				else 
					SendChatMessage("Der Spieler "..sender.. " wurde nicht gefunden.", "WHISPER", nil, sender)
					return true
				end
			end
		end
	end
	if (self:GetName() == "ChatFrame5") then
		if (gdkp.players[split] or msg == "!dkp" or msg == "?dkp") then
			return true
		end
	end
end


local function HideOutgoing(self, event, msg, author, ...)
	if (self:GetName() == "ChatFrame5") then
		if (msg == string.match(msg, "Du hast %d+ DKP aus %d+ gespielten Raids.")) then 
			UIErrorsFrame:AddMessage(author.." fragte seine DKP ab.", 1.0, 0.0, 0.0, 53, 5);
			return true	
		end
		if (msg == string.match(msg, "%w+ hat %d+ DKP aus %d+ gespielten Raids.")) then
			split = string.match(msg, "(%w+)")
			firstchar = split:sub(1,1)
			firstchar = firstchar:upper()
			split = split:sub(2)
			split = firstchar .. split
			UIErrorsFrame:AddMessage(author.." fragte "..split.."'s DKP ab.", 1.0, 0.0, 0.0, 53, 5);
			return true
		end
		if (msg == string.match(msg, "Der Spieler %w+ wurde nicht gefunden.")) then
			return true
		end
	else
		return true
	end
end

ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", HideOutgoing)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", filter)
  Reply With Quote
01-04-13, 03:16 PM   #7
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Lua Code:
  1. local function convert(s)
  2.     return (gsub(s, '.', function(c) local o = string.byte(c) return o > 127 and '\\' .. o or c end))
  3. end
  Reply With Quote
01-04-13, 04:33 PM   #8
Anja
A Fallenroot Satyr
 
Anja's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 27
someone helped me in private message, for those who search for the same answer

i used the wrong regex
%w finds only normal letters

string.match(msg, "(.+)")

finds the rest

Last edited by Anja : 01-04-13 at 04:41 PM.
  Reply With Quote
01-04-13, 06:30 PM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,315
Originally Posted by Cirax View Post
Yeah the question here is why your string contains utf8 format instead of plain text.

If it's a must to where you have to use utf8 then you would want to create a table with all the special characters in it with their utf format and then making a replace/convert function to use that table.
All strings WoW passes into the Lua environment are encoded in UTF-8. Since UTF-8 was created to be backwards compatible with ANSI, any codes within the ANSI character set will be exactly the same in UTF-8. Also, there's no reason to need a conversion function to store these in Lua. Lua supports full binary in its strings, even embedded zeroes.



Originally Posted by Anja View Post
someone helped me in private message, for those who search for the same answer

i used the wrong regex
%w finds only normal letters

string.match(msg,"(.+)")

finds the rest
The result of (.+) returns the entire contents of the string msg as it matches all characters. I would recommend using the non-space identifier (%S+) instead. Note these identifiers are case sensitive in which using the opposite case returns an inverse match. For example, since the lowercase %s returns any whitespace character, the uppercase %S would return any non-whitespace character.
__________________
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 : 01-04-13 at 06:58 PM.
  Reply With Quote
01-04-13, 07:32 PM   #10
Anja
A Fallenroot Satyr
 
Anja's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2011
Posts: 27
Lua Code:
  1. SLASH_DKP1 = "/dkp"
  2. SlashCmdList["DKP"] = function(msg, editBox)
  3.     -- change the text on the editBox.
  4.     print("Du hast "..gdkp.players.Ikuria.DKP.. "DKP")
  5. end
  6.  
  7. local function filter(self, event, msg, sender)
  8.     split = string.match(msg, " (%S+)")
  9.     if (split) then
  10.     firstchar = split:sub(1,1)
  11.     firstchar = firstchar:upper()
  12.     split = split:sub(2)
  13.     split = firstchar .. split
  14.     end
  15.     if (self:GetName() == "ChatFrame5") then
  16.         if (msg == "!dkp" or msg == "?dkp") then
  17.             if (gdkp.players[sender]) then
  18.                 SendChatMessage("Du hast "..gdkp.players[sender].DKP.. " DKP aus ".. gdkp.players[sender].rcount .. " Std. gespielter Raidzeit.", "WHISPER", nil, sender)
  19.                 return true
  20.             else
  21.                 SendChatMessage("Der Spieler "..sender.. " wurde nicht gefunden.", "WHISPER", nil, sender)
  22.                 return true
  23.             end
  24.         elseif (gdkp.players[split]) then
  25.             SendChatMessage(split.." hat "..gdkp.players[split].DKP.. " DKP aus ".. gdkp.players[split].rcount .. " Std. gespielter Raidzeit.", "WHISPER", nil, sender)
  26.             return true
  27.         end
  28.     else
  29.         if (msg == "!dkp" or msg == "?dkp") then
  30.             return true
  31.         end
  32.     end
  33. end
  34.  
  35.  
  36. local function HideOutgoing(self, event, msg, author, ...)
  37.     if (self:GetName() == "ChatFrame5") then
  38.         if (msg == string.match(msg, "Du hast %d+ DKP aus %d+ Std. gespielter Raidzeit")) then
  39.             UIErrorsFrame:AddMessage(author.." fragte seine DKP ab.", 1.0, 0.0, 0.0, 53, 5);
  40.             return true
  41.         elseif (msg == string.match(msg, ".+ hat %d+ DKP aus %d+ Std. gespielter Raidzeit.")) then
  42.             split = string.match(msg, "(%S+) hat .+")
  43.             UIErrorsFrame:AddMessage(author.." fragte "..split.."'s DKP ab.", 1.0, 0.0, 0.0, 53, 5);
  44.             return true
  45.         elseif (msg == string.match(msg, "Der Spieler (%S+) wurde nicht gefunden.")) then
  46.             return true
  47.         end
  48.     else
  49.         return true
  50.     end
  51. end
  52.  
  53. ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", HideOutgoing)
  54. ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", filter)

works, but the code is little messie ^^ just because of the "ChatFrame5" thing, i didnt know how to prevent the double posts because of same whispers in more tabs

sry for my problems here, i'm just learning lua at the moment ^^
  Reply With Quote
01-07-13, 06:13 PM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,315
I would actually recommend moving your whisper reply code into its own frame and handler. The problem with putting it in with the rest of your filter functions is those functions run for every ChatFrame that has the whisper event registered.

Another problem is if no ChatFrames are registered with the whisper event, the filter functions will never run.
__________________
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 : 01-09-13 at 06:05 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » special letters

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