- fixes german umlauts
This commit is contained in:
+12
-2
@@ -206,6 +206,15 @@ function Grichelde:ReplaceCharacters(text, replName, replTable, consolidate, rep
|
|||||||
p, patRest = getNextCharUtf8(patRest)
|
p, patRest = getNextCharUtf8(patRest)
|
||||||
end
|
end
|
||||||
ciPattern = ciPattern .. "]"
|
ciPattern = ciPattern .. "]"
|
||||||
|
elseif (isUtf8MultiByte(p)) then
|
||||||
|
-- a set like [Ää] would match single bytes, so only group the differing last byte
|
||||||
|
local upperP, lowerP = toUpper(p), toLower(p)
|
||||||
|
local lead = sub(p, 1, -2)
|
||||||
|
if (upperP ~= lowerP) and (sub(upperP, 1, -2) == lead) and (sub(lowerP, 1, -2) == lead) then
|
||||||
|
ciPattern = ciPattern .. lead .. "[" .. sub(upperP, -1) .. sub(lowerP, -1) .. "]"
|
||||||
|
else
|
||||||
|
ciPattern = ciPattern .. p
|
||||||
|
end
|
||||||
else
|
else
|
||||||
ciPattern = ciPattern .. "[" .. convertToCaseInsensitivePatternGroup(p) .. "]"
|
ciPattern = ciPattern .. "[" .. convertToCaseInsensitivePatternGroup(p) .. "]"
|
||||||
end
|
end
|
||||||
@@ -428,8 +437,9 @@ function Grichelde:ReplaceCharacters(text, replName, replTable, consolidate, rep
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- update previous consolidate markers
|
-- update previous consolidate markers
|
||||||
local diff = lengthUtf8(replText) - lengthUtf8(match)
|
-- positions are byte offsets, so the difference must be counted in bytes as well
|
||||||
self:TracePrint("ReplaceCharacters : diff = %d - %d", lengthUtf8(replText), lengthUtf8(match))
|
local diff = length(replText) - length(match)
|
||||||
|
self:TracePrint("ReplaceCharacters : diff = %d - %d", length(replText), length(match))
|
||||||
for key, posList in pairs(consolidate) do
|
for key, posList in pairs(consolidate) do
|
||||||
if (key ~= replName) then
|
if (key ~= replName) then
|
||||||
for i, pc in ipairs(posList) do
|
for i, pc in ipairs(posList) do
|
||||||
|
|||||||
+20
-2
@@ -378,6 +378,24 @@ local function getUtf8Table(word)
|
|||||||
return tbl
|
return tbl
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- handles UTF-8 characters like äöü (except ß, ÿ, × and ÷)
|
||||||
|
local function toUpper(word)
|
||||||
|
return (Grichelde.F.gsub(_G.strupper(word), "\195([\160-\190])", function(c)
|
||||||
|
if (c ~= "\183") then
|
||||||
|
return "\195" .. Grichelde.F.bytes2Char(Grichelde.F.toByte(c) - 32)
|
||||||
|
end
|
||||||
|
end))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- handles UTF-8 characters like äöü (except ß, ÿ, × and ÷)
|
||||||
|
local function toLower(word)
|
||||||
|
return (Grichelde.F.gsub(_G.strlower(word), "\195([\128-\158])", function(c)
|
||||||
|
if (c ~= "\151") then
|
||||||
|
return "\195" .. Grichelde.F.bytes2Char(Grichelde.F.toByte(c) + 32)
|
||||||
|
end
|
||||||
|
end))
|
||||||
|
end
|
||||||
|
|
||||||
local function isLetter(word)
|
local function isLetter(word)
|
||||||
local char = Grichelde.F.getNextCharUtf8(word)
|
local char = Grichelde.F.getNextCharUtf8(word)
|
||||||
return (char ~= nil) and (Grichelde.F.toUpper(char) ~= Grichelde.F.toLower(char))
|
return (char ~= nil) and (Grichelde.F.toUpper(char) ~= Grichelde.F.toLower(char))
|
||||||
@@ -514,8 +532,8 @@ Grichelde.F = {
|
|||||||
gmatch = _G.string.gmatch,
|
gmatch = _G.string.gmatch,
|
||||||
join = _G.strjoin,
|
join = _G.strjoin,
|
||||||
split = _G.strsplit,
|
split = _G.strsplit,
|
||||||
toUpper = _G.strupper,
|
toUpper = toUpper,
|
||||||
toLower = _G.strlower,
|
toLower = toLower,
|
||||||
getNextCharUtf8 = getNextCharUtf8,
|
getNextCharUtf8 = getNextCharUtf8,
|
||||||
isUtf8MultiByte = isUtf8MultiByte,
|
isUtf8MultiByte = isUtf8MultiByte,
|
||||||
getUtf8Sequence = getUtf8Sequence,
|
getUtf8Sequence = getUtf8Sequence,
|
||||||
|
|||||||
+4
-3
@@ -72,7 +72,7 @@ function Grichelde:RunTests()
|
|||||||
["OSSO"] = "OCHO",
|
["OSSO"] = "OCHO",
|
||||||
["ooSS"] = "ooCH",
|
["ooSS"] = "ooCH",
|
||||||
["schmeissen"] = "chmeichen",
|
["schmeissen"] = "chmeichen",
|
||||||
["Schön"] = "Chön",
|
["Schön"] = "Chön",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
ok = ok + o
|
ok = ok + o
|
||||||
@@ -819,8 +819,9 @@ function Grichelde:RunTests()
|
|||||||
{
|
{
|
||||||
["Hallä"] = "Hallae",
|
["Hallä"] = "Hallae",
|
||||||
["Ätsch"] = "Aetsch",
|
["Ätsch"] = "Aetsch",
|
||||||
["Hällöluü"] = "Haelloelue",
|
["Hällöluü"] = "Haelloeluue",
|
||||||
["ÜöÄ"] = "UeoeAe",
|
["ÜöÄ"] = "UeoeAE",
|
||||||
|
["Ää"] = "Aeae",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
ok = ok + o
|
ok = ok + o
|
||||||
|
|||||||
Reference in New Issue
Block a user