Permalink
Browse files

I misunderstood what finds did, and didn't spot that it was needed fo…

…r split!

Revert "string_ext: remove finds; map should be used with string.find instead"

This reverts commit 5a62e3e.
  • Loading branch information...
1 parent 5a62e3e commit 5babb5f0f8187b7652e06e9bcdfec21cbc5af3d3 @rrthomas rrthomas committed Sep 12, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/string_ext.lua
View
@@ -209,6 +209,26 @@ function tfind (s, p, init, plain)
return pack (p.find (s, p, init, plain))
end
+--- Do multiple <code>find</code>s on a string.
+-- @param s target string
+-- @param p pattern
+-- @param init start position (default: 1)
+-- @param plain inhibit magic characters (default: nil)
+-- @return list of <code>{from, to; capt = {captures}}</code>
+function finds (s, p, init, plain)
+ init = init or 1
+ local l = {}
+ local from, to, r
+ repeat
+ from, to, r = tfind (s, p, init, plain)
+ if from ~= nil then
+ table.insert (l, {from, to, capt = r})
+ init = to + 1
+ end
+ until not from
+ return l
+end
+
--- Split a string at a given separator.
-- FIXME: Consider Perl and Python versions.
-- @param s string to split

0 comments on commit 5babb5f

Please sign in to comment.