Module:languages: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 808: Line 808:
-- Remove all formatting characters.
-- Remove all formatting characters.
text = get_plaintext(text)
text = get_plaintext(text)
-- Remove all spaces and any ASCII punctuation. Some non-ASCII punctuation is script-specific, so can't be removed.
text = ugsub(text, "[%s!\"#%%&'()*,%-./:;?@[\\%]_{}]+", "")
if #text == 0 then
return get_script("None")
end


-- Try to match every script against the text,
-- Try to match every script against the text,
Line 860: Line 854:
local count = charset and length - ulen(ugsub(text, "[" .. charset .. "]+", "")) or 0
local count = charset and length - ulen(ugsub(text, "[" .. charset .. "]+", "")) or 0


if count >= length then
if match(text, "[" .. charset .. "]+") then
return sc
return sc
elseif count > bestcount then
bestcount = count
bestscript = sc
end
end
end
end

Navigation menu