diff options
-rw-r--r-- | modules/textadept/find.lua | 20 |
1 files 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. |