mirror of
https://github.com/nmap/nmap.git
synced 2025-12-11 02:09:03 +00:00
Minor optimization for caseless matching in lpeg-utility
This commit is contained in:
@@ -13,17 +13,19 @@ local pairs = pairs
|
|||||||
local string = require "string"
|
local string = require "string"
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local rawset = rawset
|
local rawset = rawset
|
||||||
|
local lower = string.lower
|
||||||
|
local upper = string.upper
|
||||||
|
|
||||||
_ENV = {}
|
_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.
|
-- Returns a pattern which matches the literal string caselessly.
|
||||||
--
|
--
|
||||||
-- @param literal A literal string to match case-insensitively.
|
-- @param literal A literal string to match case-insensitively.
|
||||||
-- @return An LPeg pattern.
|
-- @return An LPeg pattern.
|
||||||
function caseless (literal)
|
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(caselessP:match(literal))
|
||||||
return assert(caseless:match(literal))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
Reference in New Issue
Block a user