diff options
author | Sergio Queiroz <sqmedeiros@gmail.com> | 2016-07-01 14:57:39 -0300 |
---|---|---|
committer | Sergio Queiroz <sqmedeiros@gmail.com> | 2016-07-01 14:57:39 -0300 |
commit | 7cd05bfaeea0fc1d269ace114d3225bffbd82940 (patch) | |
tree | 955ed449edeed25506a3b47977840d642dad5026 /relabel.lua | |
parent | 6a3c4bfddcfaa0e1348aa2c3d9fb7135a4f330c8 (diff) | |
download | lpeglabel-7cd05bfaeea0fc1d269ace114d3225bffbd82940.tar.gz lpeglabel-7cd05bfaeea0fc1d269ace114d3225bffbd82940.tar.bz2 lpeglabel-7cd05bfaeea0fc1d269ace114d3225bffbd82940.zip |
Adding function 'calcline' to relabel and updating documentation/examples
Diffstat (limited to 'relabel.lua')
-rw-r--r-- | relabel.lua | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/relabel.lua b/relabel.lua index 003a0d2..ff2e486 100644 --- a/relabel.lua +++ b/relabel.lua | |||
@@ -433,6 +433,14 @@ local function setlabels (t) | |||
433 | tlabels = t | 433 | tlabels = t |
434 | end | 434 | end |
435 | 435 | ||
436 | local function calcline (s, i) | ||
437 | if i == 1 then return 1, 1 end | ||
438 | local rest, line = s:sub(1,i):gsub("[^\n]*\n", "") | ||
439 | local col = #rest | ||
440 | return 1 + line, col ~= 0 and col or 1 | ||
441 | end | ||
442 | |||
443 | |||
436 | -- exported names | 444 | -- exported names |
437 | local re = { | 445 | local re = { |
438 | compile = compile, | 446 | compile = compile, |
@@ -440,7 +448,8 @@ local re = { | |||
440 | find = find, | 448 | find = find, |
441 | gsub = gsub, | 449 | gsub = gsub, |
442 | updatelocale = updatelocale, | 450 | updatelocale = updatelocale, |
443 | setlabels = setlabels | 451 | setlabels = setlabels, |
452 | calcline = calcline | ||
444 | } | 453 | } |
445 | 454 | ||
446 | if version == "Lua 5.1" then _G.re = re end | 455 | if version == "Lua 5.1" then _G.re = re end |