From 9292a335d7a9dfd102c10ca66a1210aa39ac3739 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+orbitalquark@users.noreply.github.com> Date: Tue, 13 Oct 2020 00:24:16 -0400 Subject: Construct regex replacement pattern from previous commit just once. --- modules/textadept/find.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index a71faa26..5590e356 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -381,6 +381,15 @@ local function unescape(text) end) or text end +local P, V, upper, lower = lpeg.P, lpeg.V, string.upper, string.lower +local re_patt = lpeg.Cs(P{ + (V('text') + V('u') + V('l') + V('U') + V('L'))^1, + text = (1 - '\\' * lpeg.S('uUlLE'))^1, + u = '\\u' * lpeg.C(1) / upper, l = '\\l' * lpeg.C(1) / lower, + U = P('\\U') / '' * (V('text') / upper + V('u') + V('l'))^0 * V('E')^-1, + L = P('\\L') / '' * (V('text') / lower + V('u') + V('l'))^0 * V('E')^-1, + E = P('\\E') / '', +}) -- Replaces the text in the target range with string *text* subject to: -- * "\d" sequences replaced with the text of capture number *d* from the -- regular expression (or the entire match for *d* = 0) @@ -390,16 +399,7 @@ end -- lowercase, respectively. They may appear within "\U" and "\L" constructs. local function replace_target_re(buffer, rtext) rtext = rtext:gsub('\\0', buffer.target_text):gsub('\\(%d)', buffer.tag) - local P, V, upper, lower = lpeg.P, lpeg.V, string.upper, string.lower - local patt = lpeg.Cs(P{ - (V('text') + V('u') + V('l') + V('U') + V('L'))^1, - text = (1 - '\\' * lpeg.S('uUlLE'))^1, - u = '\\u' * lpeg.C(1) / upper, l = '\\l' * lpeg.C(1) / lower, - U = P('\\U') / '' * (V('text') / upper + V('u') + V('l'))^0 * V('E')^-1, - L = P('\\L') / '' * (V('text') / lower + V('u') + V('l'))^0 * V('E')^-1, - E = P('\\E') / '', - }) - buffer:replace_target(lpeg.match(patt, rtext) or rtext) + buffer:replace_target(lpeg.match(re_patt, rtext) or rtext) end -- Replaces found (selected) text. -- cgit v1.2.3