[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: string.gsub (Lua 5.1.1)
- From: Shmuel Zeigerman <shmuz@...>
- Date: Mon, 06 Nov 2006 09:33:36 +0200
Nick Gammon wrote:
Probably the manual should be reworded as:
"gsub also returns, as its second value, the total number of matches made."
But this would be, in fact, an API alteration, and API is not allowed to
change after the Lua version is officially out.
Alternatively, change the behaviour of Lua to actually not count the
cases where the replacement isn't made. However in that case, do you
count this example:
string.gsub ("a", "a", "a")
You could argue that replacing "a" by "a" is not really replacing it.
I think gsub itself should be agnostic in regard to whether the
replacing string is equal to the match. It is up to the application to
be (or not to be) interested in that.
Let's see another example:
print (string.gsub ("abc123", "(.)",
local n = tonumber(c)
return n and n+1
It seems returning "abc234", 3 would make more sense.