PDA

View Full Version : Single/Plural string returns.


voyseys
18-05-2008, 10:44 PM
Thanks to Blizzard's attempt at setting up Singular/Plural strings, it has broken SendChatMessage() strings (It cannot handle \124). The new string will have to be rebuilt for the function to work properly.

So, while fixing Ding Recorder to work with 2.4.2 I came up with this little function. Admittedly it is geared more towards towards the SecondsToTime() function. Though with a small amount of playing, I'm sure someone could make use of it.

- - - -

function dingrecorder_rebuild(incstr)

local outstr = "";

local start, stop, num, single, plural = incstr:find("(%d-) \1244(.-):(.-);");

if start then
outstr = num .. " "
if tonumber(num) > 1 then
outstr = outstr .. plural;
else
outstr = outstr .. single;
end

if strlen(incstr) > stop + 1 then
outstr = outstr .. " " .. dingrecorder_rebuild(strsub(incstr, stop + 1));
end
end

return(outstr);
end

- - - -

Be careful with it, It's a recusive function. :grin:

By the way, that :find pattern system is a very powerful. I was expecting to use a lot of strlen's and strsub's for this one. :laughing:

Enjoy