diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-01-08 14:22:32 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-01-08 14:22:32 -0200 |
commit | 264659bd53e92969a1e17d65c0266597cde24b5d (patch) | |
tree | 6aba62d2b6ac2a46dc064ea7193c8134200a7d57 /testes/pm.lua | |
parent | 4ace93ca6502dd1da38d5c06fa099d229e791ba8 (diff) | |
download | lua-264659bd53e92969a1e17d65c0266597cde24b5d.tar.gz lua-264659bd53e92969a1e17d65c0266597cde24b5d.tar.bz2 lua-264659bd53e92969a1e17d65c0266597cde24b5d.zip |
Optional 'init' argument to 'string.gmatch'
The function 'string.gmatch' now has an optional 'init' argument,
similar to 'string.find' and 'string.match'. Moreover, there was
some reorganization in the manipulation of indices in the string
library.
This commit also includes small janitorial work in the manual
and in comments in the interpreter loop.
Diffstat (limited to 'testes/pm.lua')
-rw-r--r-- | testes/pm.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/testes/pm.lua b/testes/pm.lua index 1afaccf6..8cc8772e 100644 --- a/testes/pm.lua +++ b/testes/pm.lua | |||
@@ -297,6 +297,35 @@ for k,v in pairs(t) do assert(k+1 == v+0); a=a+1 end | |||
297 | assert(a == 3) | 297 | assert(a == 3) |
298 | 298 | ||
299 | 299 | ||
300 | do -- init parameter in gmatch | ||
301 | local s = 0 | ||
302 | for k in string.gmatch("10 20 30", "%d+", 3) do | ||
303 | s = s + tonumber(k) | ||
304 | end | ||
305 | assert(s == 50) | ||
306 | |||
307 | s = 0 | ||
308 | for k in string.gmatch("11 21 31", "%d+", -4) do | ||
309 | s = s + tonumber(k) | ||
310 | end | ||
311 | assert(s == 32) | ||
312 | |||
313 | -- there is an empty string at the end of the subject | ||
314 | s = 0 | ||
315 | for k in string.gmatch("11 21 31", "%w*", 9) do | ||
316 | s = s + 1 | ||
317 | end | ||
318 | assert(s == 1) | ||
319 | |||
320 | -- there are no empty strings after the end of the subject | ||
321 | s = 0 | ||
322 | for k in string.gmatch("11 21 31", "%w*", 10) do | ||
323 | s = s + 1 | ||
324 | end | ||
325 | assert(s == 0) | ||
326 | end | ||
327 | |||
328 | |||
300 | -- tests for `%f' (`frontiers') | 329 | -- tests for `%f' (`frontiers') |
301 | 330 | ||
302 | assert(string.gsub("aaa aa a aaa a", "%f[%w]a", "x") == "xaa xa x xaa x") | 331 | assert(string.gsub("aaa aa a aaa a", "%f[%w]a", "x") == "xaa xa x xaa x") |