From 3cfe60c3ed56484dbe09e27a172d1ecc6acd3656 Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 8 Sep 2022 18:14:52 +0000 Subject: [PATCH] Minor optimization for caseless matching in lpeg-utility --- nselib/lpeg-utility.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nselib/lpeg-utility.lua b/nselib/lpeg-utility.lua index 88acfd74b..47134bc1f 100644 --- a/nselib/lpeg-utility.lua +++ b/nselib/lpeg-utility.lua @@ -13,17 +13,19 @@ local pairs = pairs local string = require "string" local tonumber = tonumber local rawset = rawset +local lower = string.lower +local upper = string.upper _ENV = {} +local caselessP = lpeg.Cf((lpeg.P(1) / function (a) return lpeg.S(lower(a)..upper(a)) end)^1, function (a, b) return a * b end) --- -- Returns a pattern which matches the literal string caselessly. -- -- @param literal A literal string to match case-insensitively. -- @return An LPeg pattern. function caseless (literal) - local caseless = lpeg.Cf((lpeg.P(1) / function (a) return lpeg.S(a:lower()..a:upper()) end)^1, function (a, b) return a * b end) - return assert(caseless:match(literal)) + return assert(caselessP:match(literal)) end ---