vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 ****************************************************************
3 SCT Globalization Format Parser
4  
5 Some of this code was directly taken from MarsMessageParser.lua
6 with permission from the author (as said in the file).
7  
8 It used is being used by SCT simply to make sure all the
9 GlobalStrings.lua strings are ordered and converted properly.
10  
11 ****************************************************************]]
12  
13  
14 local SCT_GlobalStrings = {};
15 local ParseFunction;
16 local parseBuffer;
17 local parseOrder;
18 local parseCount;
19  
20 ParseFunction = function (character)
21 local result;
22 if(not parseBuffer) then
23 if(character == "%") then
24 parseBuffer = character;
25 result = "";
26 else
27 if(string.find(character, "[%^%$%(%)%%%.%[%]%*%+%-%?]")) then
28 result = "%"..character;
29 else
30 result = character;
31 end
32 end
33 else
34 parseBuffer = parseBuffer..character;
35 if(string.find(character, "[%%cEefgGiouXxqs]")) then
36 local order;
37 _, _, order = string.find(parseBuffer, "(%d+)%$");
38 parseCount = parseCount + 1;
39 if(order) then
40 parseOrder[parseCount] = tonumber(order);
41 else
42 parseOrder[parseCount] = parseCount;
43 end
44 result = "(.+)";
45 parseBuffer = nil;
46 elseif(string.find(character, "[%%d]")) then
47 local order;
48 _, _, order = string.find(parseBuffer, "(%d+)%$");
49 parseCount = parseCount + 1;
50 if(order) then
51 parseOrder[parseCount] = tonumber(order);
52 else
53 parseOrder[parseCount] = parseCount;
54 end
55 result = "(%d+)";
56 parseBuffer = nil;
57 elseif(string.find(character, "[%$%.%d]")) then
58 result = "";
59 else
60 result = parseBuffer;
61 parseBuffer = nil;
62 end
63 end
64 return result;
65 end
66  
67 function SCTGlobalParser_Format(formatString)
68 parseBuffer = nil;
69 parseOrder = {};
70 parseCount = 0;
71  
72 --see if in "cache" table
73 if (SCT_GlobalStrings[formatString] == nil) then
74 local parseString = string.gsub(formatString, ".", ParseFunction);
75 SCT_GlobalStrings[formatString] = { parseString, parseOrder };
76 end
77  
78 return SCT_GlobalStrings[formatString];
79 end
80  
81 function SCTGlobalParser_ParseMessage(arg1, formatString)
82 local parseResult;
83 local findResult;
84  
85 parseResult = SCTGlobalParser_Format(formatString);
86 findResult = {string.find(arg1, parseResult[1])};
87 if(findResult[1]) then
88 local i, n;
89 local callResult = {};
90 n = table.getn(findResult);
91 for i=3,n do
92 callResult[parseResult[2][i-2]] = findResult[i];
93 end
94 return unpack(callResult);
95 end
96 return nil;
97 end
98  
99