48,355
edits
No edit summary |
|||
| Line 803: | Line 803: | ||
first_sc = get_script(first_sc) | first_sc = get_script(first_sc) | ||
local charset = first_sc.characters | local charset = first_sc.characters | ||
return charset and first_sc or get_script("None") | return charset and umatch(text, "[" .. charset .. "]") and first_sc or get_script("None") | ||
end | end | ||
-- Remove all formatting characters. | -- Remove all formatting characters. | ||
text = get_plaintext(text) | text = get_plaintext(text) | ||
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, | ||
-- and return the one with the most matching characters. | -- and return the one with the most matching characters. | ||
local bestcount | local bestscript | ||
local bestcount, length = 0, 0 | |||
for i = 1, codes_len do | for i = 1, codes_len do | ||
local sc = codes[i] | local sc = codes[i] | ||
| Line 854: | Line 859: | ||
local count = charset and length - ulen(ugsub(text, "[" .. charset .. "]+", "")) or 0 | local count = charset and length - ulen(ugsub(text, "[" .. charset .. "]+", "")) or 0 | ||
if | if count >= length then | ||
return sc | return sc | ||
elseif count > bestcount then | |||
bestcount = count | |||
bestscript = sc | |||
end | end | ||
end | end | ||