diff options
author | Hans Hagen <pragma@wxs.nl> | 2018-03-15 16:04:31 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2018-03-15 16:04:31 +0100 |
commit | a4e07f30e880ab27c2918f81f136e257475b7729 (patch) | |
tree | 02db002d3001a49777a049f9a98fdc872a5e1ad1 /tex/context/base/mkiv/data-tex.lua | |
parent | cbc37c39432e0ebe38e0922fc6d14c2955ab3ba2 (diff) | |
download | context-a4e07f30e880ab27c2918f81f136e257475b7729.tar.gz |
2018-03-15 15:36:00
Diffstat (limited to 'tex/context/base/mkiv/data-tex.lua')
-rw-r--r-- | tex/context/base/mkiv/data-tex.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/data-tex.lua b/tex/context/base/mkiv/data-tex.lua index b6b97a0a9..2d2c9b24d 100644 --- a/tex/context/base/mkiv/data-tex.lua +++ b/tex/context/base/mkiv/data-tex.lua @@ -57,6 +57,33 @@ resolvers.inputstack = resolvers.inputstack or { } local inputstack = resolvers.inputstack +---------------------------------------- + +local lpegmatch = lpeg.match +local newline = lpeg.patterns.newline +local tsplitat = lpeg.tsplitat + +local linesplitters = { + tsplitat(newline), -- default since we started + tsplitat(lpeg.S(" ")^0 * newline), + tsplitat(lpeg.S(" \t")^0 * newline), + tsplitat(lpeg.S(" \f\t")^0 * newline), -- saves a bit of space at the cost of runtime + -- tsplitat(lpeg.S(" \v\f\t")^0 * newline), + -- tsplitat(lpeg.R("\0\31")^0 * newline), +} + +local linesplitter = linesplitters[1] + +directives.register("system.linesplitmethod",function(v) + linesplitter = linesplitters[tonumber(v) or 1] or linesplitters[1] +end) + +local function splitlines(str) + return lpegmatch(linesplitter,str) +end + +----------------------------------------- + function helpers.textopener(tag,filename,filehandle,coding) local lines local t_filehandle = type(filehandle) |