diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2015-05-04 23:10:29 +0200 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2015-05-04 23:11:06 +0200 |
commit | a79c845dba381f543d09526f77dcf2b4687b73a7 (patch) | |
tree | 8c42403a55c9c6736eb491331bfa7f650f807414 /lualibs-util-str.lua | |
parent | 9c35a373aa8e0edf14b686568fffab0e6969f447 (diff) | |
download | lualibs-a79c845dba381f543d09526f77dcf2b4687b73a7.tar.gz |
sync with Context as of 2015-05-04
Diffstat (limited to 'lualibs-util-str.lua')
-rw-r--r-- | lualibs-util-str.lua | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lualibs-util-str.lua b/lualibs-util-str.lua index a677a82..de4a87e 100644 --- a/lualibs-util-str.lua +++ b/lualibs-util-str.lua @@ -44,7 +44,12 @@ end if not number then number = { } end -- temp hack for luatex-fonts -local stripper = patterns.stripzeros +local stripper = patterns.stripzeros +local newline = patterns.newline +local endofstring = patterns.endofstring +local whitespace = patterns.whitespace +local spacer = patterns.spacer +local spaceortab = patterns.spaceortab local function points(n) n = tonumber(n) @@ -62,12 +67,12 @@ number.basepoints = basepoints -- str = " \n \ntest \n test\ntest " -- print("["..string.gsub(string.collapsecrlf(str),"\n","+").."]") -local rubish = patterns.spaceortab^0 * patterns.newline -local anyrubish = patterns.spaceortab + patterns.newline +local rubish = spaceortab^0 * newline +local anyrubish = spaceortab + newline local anything = patterns.anything -local stripped = (patterns.spaceortab^1 / "") * patterns.newline +local stripped = (spaceortab^1 / "") * newline local leading = rubish^0 / "" -local trailing = (anyrubish^1 * patterns.endofstring) / "" +local trailing = (anyrubish^1 * endofstring) / "" local redundant = rubish^3 / "\n" local pattern = Cs(leading * (trailing + redundant + stripped + anything)^0) @@ -129,7 +134,7 @@ local pattern = return "" end end - + patterns.newline * Cp() / function(position) + + newline * Cp() / function(position) extra, start = 0, position end + patterns.anything @@ -162,11 +167,6 @@ end -- return str -- end -local newline = patterns.newline -local endofstring = patterns.endofstring -local whitespace = patterns.whitespace -local spacer = patterns.spacer - local space = spacer^0 local nospace = space/"" local endofline = nospace * newline @@ -1117,3 +1117,9 @@ local pattern = function string.optionalquoted(str) return lpegmatch(pattern,str) or str end + +local pattern = Cs((newline / os.newline + 1)^0) + +function string.replacenewlines(str) + return lpegmatch(pattern,str) +end |