Version 0.7.0-beta
- order buttons - use numeric LogLevel over booleans - exact case option reversed (again) - smart case handling if replacement is longer than match - Deletion of all mappings
This commit is contained in:
@@ -210,7 +210,36 @@ function Grichelde:ReplaceCharacters(text)
|
||||
local replace = replTable.replaceText
|
||||
consolidate[replName] = {}
|
||||
|
||||
if replTable.ignoreCase then
|
||||
if replTable.exactCase then
|
||||
-- exact case
|
||||
self:DebugPrint("ReplaceCharacters : \"%s => %s\" (exact case)", search, replace)
|
||||
local pos, offset = 1, 0
|
||||
local oldResult = result
|
||||
|
||||
local pos1, pos2 = find(oldResult, search, pos)
|
||||
while (pos1 and pos2) do
|
||||
self:TracePrint("pos1: %d, pos2: %d", pos1, pos2)
|
||||
local pre = sub(result, 1, pos1 - 1 + offset)
|
||||
local post = sub(result, pos2 + 1 + offset)
|
||||
self:TracePrint("pre: %s, post: %s", pre, post)
|
||||
|
||||
-- actual replacement
|
||||
result = pre .. replace .. post
|
||||
self:DebugPrint("result: %s", result)
|
||||
|
||||
-- remember positions for consolidate
|
||||
if replTable.consolidate then
|
||||
tInsert(consolidate[replName], pos1 + offset)
|
||||
end
|
||||
|
||||
-- replacement text can lengthen or shorten the resulting text
|
||||
-- after replacement result and lowerResult can have different sizes
|
||||
offset = offset + length(replace) - length(search)
|
||||
-- update values for next iteration
|
||||
pos = pos2 + 1
|
||||
pos1, pos2 = find(oldResult, search, pos)
|
||||
end
|
||||
else
|
||||
self:DebugPrint("ReplaceCharacters : \"%s => %s\" (ignoreCase)", search, replace)
|
||||
local pos, offset = 1, 0
|
||||
local lowerResult = toLower(result)
|
||||
@@ -253,19 +282,26 @@ function Grichelde:ReplaceCharacters(text)
|
||||
self:TracePrint("rest: %s, n: %s, lastCase: %s", remainingReplace, nextLetter, lastCase)
|
||||
|
||||
if (isUpper(nextLetter)) then
|
||||
repl = repl .. toUpper(remainingReplace)
|
||||
if lastCase == nil or lastCase == false then
|
||||
repl = repl .. remainingReplace
|
||||
else
|
||||
repl = repl .. toUpper(remainingReplace)
|
||||
end
|
||||
elseif (isLower(nextLetter)) then
|
||||
repl = repl .. toLower(remainingReplace)
|
||||
if lastCase == nil or lastCase == true then
|
||||
repl = repl .. remainingReplace
|
||||
else
|
||||
repl = repl .. toLower(remainingReplace)
|
||||
end
|
||||
else
|
||||
-- no letter
|
||||
repl = repl .. remainingReplace
|
||||
-- if lastCase == nil then
|
||||
-- repl = repl .. remainingReplace
|
||||
-- elseif lastCase == false then
|
||||
-- repl = repl .. toLower(remainingReplace)
|
||||
-- else
|
||||
-- repl = repl .. toUpper(remainingReplace)
|
||||
-- end
|
||||
if lastCase == nil then
|
||||
repl = repl .. remainingReplace
|
||||
elseif lastCase == false then
|
||||
repl = repl .. toLower(remainingReplace)
|
||||
else
|
||||
repl = repl .. toUpper(remainingReplace)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -285,35 +321,6 @@ function Grichelde:ReplaceCharacters(text)
|
||||
pos = pos2 + 1
|
||||
pos1, pos2 = find(lowerResult, lowerSearch, pos)
|
||||
end
|
||||
else
|
||||
-- exact case
|
||||
self:DebugPrint("ReplaceCharacters : \"%s => %s\" (exact case)", search, replace)
|
||||
local pos, offset = 1, 0
|
||||
local oldResult = result
|
||||
|
||||
local pos1, pos2 = find(oldResult, search, pos)
|
||||
while (pos1 and pos2) do
|
||||
self:TracePrint("pos1: %d, pos2: %d", pos1, pos2)
|
||||
local pre = sub(result, 1, pos1 - 1 + offset)
|
||||
local post = sub(result, pos2 + 1 + offset)
|
||||
self:TracePrint("pre: %s, post: %s", pre, post)
|
||||
|
||||
-- actual replacement
|
||||
result = pre .. replace .. post
|
||||
self:DebugPrint("result: %s", result)
|
||||
|
||||
-- remember positions for consolidate
|
||||
if replTable.consolidate then
|
||||
tInsert(consolidate[replName], pos1 + offset)
|
||||
end
|
||||
|
||||
-- replacement text can lengthen or shorten the resulting text
|
||||
-- after replacement result and lowerResult can have different sizes
|
||||
offset = offset + length(replace) - length(search)
|
||||
-- update values for next iteration
|
||||
pos = pos2 + 1
|
||||
pos1, pos2 = find(oldResult, search, pos)
|
||||
end
|
||||
end
|
||||
|
||||
if before ~= result then
|
||||
|
||||
Reference in New Issue
Block a user