45,646
edits
No edit summary |
No edit summary |
||
Line 60: | Line 60: | ||
(indicating a missing code). If `not_real_lang` is given, this check is suppressed. | (indicating a missing code). If `not_real_lang` is given, this check is suppressed. | ||
]=] | ]=] | ||
-- Process carets (and any escapes). Default to simple removal, if no pattern/replacement is given. | |||
local function processCarets(text, pattern, repl) | |||
local rep | |||
repeat | |||
text, rep = gsub(text, "\\\\(\\*^)", "\3%1") | |||
until rep == 0 | |||
return text:gsub("\\^", "\4") | |||
:gsub(pattern or "%^", repl or "") | |||
:gsub("\3", "\\") | |||
:gsub("\4", "^") | |||
end | |||
-- Remove carets if they are used to capitalize parts of transliterations (unless they have been escaped). | |||
local function removeCarets(text, sc) | |||
if not sc:hasCapitalization() and sc:isTransliterated() and text:find("^", 1, true) then | |||
return processCarets(text) | |||
else | |||
return text | |||
end | |||
end | |||
-- Temporarily convert various formatting characters to PUA to prevent them from being disrupted by the substitution process. | -- Temporarily convert various formatting characters to PUA to prevent them from being disrupted by the substitution process. |