summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/l-string.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/l-string.lua')
-rw-r--r--tex/context/base/mkiv/l-string.lua39
1 files changed, 33 insertions, 6 deletions
diff --git a/tex/context/base/mkiv/l-string.lua b/tex/context/base/mkiv/l-string.lua
index e9dc2bbbc..e0fb28445 100644
--- a/tex/context/base/mkiv/l-string.lua
+++ b/tex/context/base/mkiv/l-string.lua
@@ -72,22 +72,27 @@ end
local stripper = patterns.stripper
local fullstripper = patterns.fullstripper
local collapser = patterns.collapser
+local nospacer = patterns.nospacer
local longtostring = patterns.longtostring
function string.strip(str)
- return lpegmatch(stripper,str) or ""
+ return str and lpegmatch(stripper,str) or ""
end
function string.fullstrip(str)
- return lpegmatch(fullstripper,str) or ""
+ return str and lpegmatch(fullstripper,str) or ""
end
function string.collapsespaces(str)
- return lpegmatch(collapser,str) or ""
+ return str and lpegmatch(collapser,str) or ""
+end
+
+function string.nospaces(str)
+ return str and lpegmatch(nospacer,str) or ""
end
function string.longtostring(str)
- return lpegmatch(longtostring,str) or ""
+ return str and lpegmatch(longtostring,str) or ""
end
-- function string.is_empty(str)
@@ -99,7 +104,7 @@ local pattern = P(" ")^0 * P(-1) -- maybe also newlines
-- patterns.onlyspaces = pattern
function string.is_empty(str)
- if str == "" then
+ if not str or str == "" then
return true
else
return lpegmatch(pattern,str) and true or false
@@ -163,7 +168,7 @@ function string.escapedpattern(str,simple)
end
function string.topattern(str,lowercase,strict)
- if str=="" or type(str) ~= "string" then
+ if str == "" or type(str) ~= "string" then
return ".*"
elseif strict then
str = lpegmatch(pattern_c,str)
@@ -177,6 +182,7 @@ function string.topattern(str,lowercase,strict)
end
end
+-- print(string.escapedpattern("abc*234",true))
-- print(string.escapedpattern("12+34*.tex",false))
-- print(string.escapedpattern("12+34*.tex",true))
-- print(string.topattern ("12+34*.tex",false,false))
@@ -211,3 +217,24 @@ end
string.quote = string.quoted
string.unquote = string.unquoted
+
+-- new
+
+if not string.bytetable then
+
+ local limit = 5000 -- we can go to 8000 in luajit and much higher in lua if needed
+
+ function string.bytetable(str)
+ local n = #str
+ if n > limit then
+ local t = { byte(str,1,limit) }
+ for i=limit+1,n do
+ t[i] = byte(str,i)
+ end
+ return t
+ else
+ return { byte(str,1,n) }
+ end
+ end
+
+end