<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://odden.us:443/thadar/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AScripts%2FcharToScript</id>
	<title>Module:Scripts/charToScript - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://odden.us:443/thadar/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AScripts%2FcharToScript"/>
	<link rel="alternate" type="text/html" href="https://odden.us:443/thadar/wiki/index.php?title=Module:Scripts/charToScript&amp;action=history"/>
	<updated>2026-04-12T15:04:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://odden.us:443/thadar/wiki/index.php?title=Module:Scripts/charToScript&amp;diff=1188&amp;oldid=prev</id>
		<title>Oa10712: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://odden.us:443/thadar/wiki/index.php?title=Module:Scripts/charToScript&amp;diff=1188&amp;oldid=prev"/>
		<updated>2022-09-06T03:34:46Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:34, 5 September 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Oa10712</name></author>
	</entry>
	<entry>
		<id>https://odden.us:443/thadar/wiki/index.php?title=Module:Scripts/charToScript&amp;diff=1187&amp;oldid=prev</id>
		<title>en&gt;Surjection at 13:50, 26 January 2022</title>
		<link rel="alternate" type="text/html" href="https://odden.us:443/thadar/wiki/index.php?title=Module:Scripts/charToScript&amp;diff=1187&amp;oldid=prev"/>
		<updated>2022-01-26T13:50:08Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local subexport = {}&lt;br /&gt;
&lt;br /&gt;
-- Copied from [[Module:Unicode data]].&lt;br /&gt;
local floor = math.floor&lt;br /&gt;
local function binaryRangeSearch(codepoint, ranges)&lt;br /&gt;
	local low, mid, high&lt;br /&gt;
	low, high = 1, ranges.length or require &amp;quot;Module:table&amp;quot;.length(ranges)&lt;br /&gt;
	while low &amp;lt;= high do&lt;br /&gt;
		mid = floor((low + high) / 2)&lt;br /&gt;
		local range = ranges[mid]&lt;br /&gt;
		if codepoint &amp;lt; range[1] then&lt;br /&gt;
			high = mid - 1&lt;br /&gt;
		elseif codepoint &amp;lt;= range[2] then&lt;br /&gt;
			return range, mid&lt;br /&gt;
		else&lt;br /&gt;
			low = mid + 1&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return nil, mid&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Copied from [[Module:Unicode data]].&lt;br /&gt;
local function linearRangeSearch(codepoint, ranges)&lt;br /&gt;
	for i, range in ipairs(ranges) do&lt;br /&gt;
		if codepoint &amp;lt; range[1] then&lt;br /&gt;
			break&lt;br /&gt;
		elseif codepoint &amp;lt;= range[2] then&lt;br /&gt;
			return range&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function compareRanges(range1, range2)&lt;br /&gt;
	return range1[1] &amp;lt; range2[1]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Save previously used codepoint ranges in case another character is in the&lt;br /&gt;
-- same range.&lt;br /&gt;
local rangesCache = {}&lt;br /&gt;
&lt;br /&gt;
--[=[&lt;br /&gt;
	Takes a codepoint or a character and finds the script code (if any) that is&lt;br /&gt;
	appropriate for it based on the codepoint, using the data module&lt;br /&gt;
	[[Module:scripts/recognition data]]. The data module was generated from the&lt;br /&gt;
	patterns in [[Module:scripts/data]] using [[Module:User:Erutuon/script recognition]].&lt;br /&gt;
&lt;br /&gt;
	Converts the character to a codepoint. Returns a script code if the codepoint&lt;br /&gt;
	is in the list of individual characters, or if it is in one of the defined&lt;br /&gt;
	ranges in the 4096-character block that it belongs to, else returns &amp;quot;None&amp;quot;.&lt;br /&gt;
]=]&lt;br /&gt;
local charToScriptData&lt;br /&gt;
function subexport.charToScript(char)&lt;br /&gt;
	charToScriptData = charToScriptData or mw.loadData(&amp;quot;Module:scripts/recognition data&amp;quot;)&lt;br /&gt;
	local t = type(char)&lt;br /&gt;
	local codepoint&lt;br /&gt;
	if t == &amp;quot;string&amp;quot; then&lt;br /&gt;
		local etc&lt;br /&gt;
		codepoint, etc = mw.ustring.codepoint(char, 1, 2)&lt;br /&gt;
		if etc then&lt;br /&gt;
			error(&amp;quot;bad argument #1 to &amp;#039;charToScript&amp;#039; (expected a single character)&amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
	elseif t == &amp;quot;number&amp;quot; then&lt;br /&gt;
		codepoint = char&lt;br /&gt;
	else&lt;br /&gt;
		error((&amp;quot;bad argument #1 to &amp;#039;charToScript&amp;#039; (expected string or a number, got %s)&amp;quot;)&lt;br /&gt;
			:format(t))&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local individualMatch = charToScriptData.individual[codepoint]&lt;br /&gt;
	if individualMatch then&lt;br /&gt;
		return individualMatch&lt;br /&gt;
	else&lt;br /&gt;
		local range&lt;br /&gt;
		if rangesCache[1] then&lt;br /&gt;
			range = linearRangeSearch(codepoint, rangesCache)&lt;br /&gt;
			if range then&lt;br /&gt;
				return range[3]&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		local index = floor(codepoint / 0x1000)&lt;br /&gt;
&lt;br /&gt;
		range = linearRangeSearch(index, charToScriptData.blocks)&lt;br /&gt;
		if not range and charToScriptData[index] then&lt;br /&gt;
			range = binaryRangeSearch(codepoint, charToScriptData[index])&lt;br /&gt;
			if range then&lt;br /&gt;
				table.insert(rangesCache, range)&lt;br /&gt;
				table.sort(rangesCache, compareRanges)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		return range and range[3] or &amp;quot;None&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function subexport.findBestScriptWithoutLang(text)&lt;br /&gt;
	local scripts = {}&lt;br /&gt;
	for character in text:gmatch(&amp;quot;[%z\1-\127\194-\244][\128-\191]*&amp;quot;) do&lt;br /&gt;
		local script = subexport.charToScript(character)&lt;br /&gt;
		scripts[script] = (scripts[script] or 0) + 1&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local bestScript&lt;br /&gt;
	local greatestCount = 0&lt;br /&gt;
	for script, count in pairs(scripts) do&lt;br /&gt;
		if count &amp;gt; greatestCount then&lt;br /&gt;
			bestScript = script&lt;br /&gt;
			greatestCount = count&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return bestScript&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return subexport&lt;/div&gt;</summary>
		<author><name>en&gt;Surjection</name></author>
	</entry>
</feed>