<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3ACollation</id>
	<title>Module:Collation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3ACollation"/>
	<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:Collation&amp;action=history"/>
	<updated>2026-04-05T14:08:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://linguifex.com/w/index.php?title=Module:Collation&amp;diff=214834&amp;oldid=prev</id>
		<title>Chrysophylax: Created page with &quot;local export = {}  -- Custom functions for generating a sortkey that will achieve the desired sort -- order. -- name of module and name of exported function local custom_sort_...&quot;</title>
		<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:Collation&amp;diff=214834&amp;oldid=prev"/>
		<updated>2021-01-02T04:23:12Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local export = {}  -- Custom functions for generating a sortkey that will achieve the desired sort -- order. -- name of module and name of exported function local custom_sort_...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local export = {}&lt;br /&gt;
&lt;br /&gt;
-- Custom functions for generating a sortkey that will achieve the desired sort&lt;br /&gt;
-- order.&lt;br /&gt;
-- name of module and name of exported function&lt;br /&gt;
local custom_sort_functions = {&lt;br /&gt;
	egy = { &amp;quot;egy-utilities&amp;quot;, &amp;quot;make_sortkey&amp;quot; },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function is_lang_object(lang)&lt;br /&gt;
	return type(lang) == &amp;quot;table&amp;quot; and type(lang.getCanonicalName) == &amp;quot;function&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function check_lang_object(funcName, argIdx, lang)&lt;br /&gt;
	if not is_lang_object(lang) then&lt;br /&gt;
		error(&amp;quot;bad argument #&amp;quot; .. argIdx .. &amp;quot; to &amp;quot; .. funcName&lt;br /&gt;
			.. &amp;quot;: expected language object, got &amp;quot; .. type(lang) .. &amp;quot;.&amp;quot;, 2)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- UTF-8-encoded characters that do not belong to the Basic Multilingual Plane&lt;br /&gt;
-- (that is, with code points greater than U+FFFF) have byte sequences that&lt;br /&gt;
-- begin with the bytes 240 to 244.&lt;br /&gt;
local function contains_non_BMP(str)&lt;br /&gt;
	return str:find &amp;#039;[\240-\244]&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
do&lt;br /&gt;
	local byte, min = string.byte, math.min&lt;br /&gt;
	function export.laborious_comp(item1, item2)&lt;br /&gt;
		local l1, l2 = #item1, #item2&lt;br /&gt;
		for i = 1, min(l1, l2) do&lt;br /&gt;
			local char1, char2 = byte(item1, i, i), byte(item2, i, i)&lt;br /&gt;
			if char1 ~= char2 then&lt;br /&gt;
				return char1 &amp;lt; char2&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return l1 &amp;lt; l2&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function export.make_sortkey_func(lang)&lt;br /&gt;
	check_lang_object(&amp;quot;make_sortkey_func&amp;quot;, 1, lang)&lt;br /&gt;
	&lt;br /&gt;
	local cache = {}&lt;br /&gt;
	&lt;br /&gt;
	local custom_sort_function = custom_sort_functions[lang:getCode()]&lt;br /&gt;
	local makeSortKey =&lt;br /&gt;
		custom_sort_function and require(&amp;quot;Module:&amp;quot; .. custom_sort_function[1])[custom_sort_function[2]]&lt;br /&gt;
		or function(text)&lt;br /&gt;
			return lang:makeSortKey(text)&lt;br /&gt;
		end&lt;br /&gt;
	&lt;br /&gt;
	local m_links = require(&amp;quot;Module:links&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	return function (element)&lt;br /&gt;
		local result = cache[element]&lt;br /&gt;
		&lt;br /&gt;
		if result then&lt;br /&gt;
			return result&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		result = m_links.remove_links(element)&lt;br /&gt;
		result = mw.ustring.gsub(result, &amp;quot;[%p ]&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
		result = makeSortKey(lang:makeEntryName(result))&lt;br /&gt;
		cache[element] = result&lt;br /&gt;
		&lt;br /&gt;
		return result&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function export.make_compare_func(lang, non_BMP)&lt;br /&gt;
	check_lang_object(&amp;quot;make_compare_func&amp;quot;, 1, lang)&lt;br /&gt;
	&lt;br /&gt;
	local make_sortkey = export.make_sortkey_func(lang)&lt;br /&gt;
	&lt;br /&gt;
	-- When comparing two elements with code points outside the BMP, the&lt;br /&gt;
	-- less-than operator does not work correctly because of a bug in glibc.&lt;br /&gt;
	-- See [[phab:T193096]].&lt;br /&gt;
	if non_BMP then&lt;br /&gt;
		return function (elem1, elem2)&lt;br /&gt;
			return export.laborious_comp(make_sortkey(elem1), make_sortkey(elem2))&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return function (elem1, elem2)&lt;br /&gt;
			return make_sortkey(elem1) &amp;lt; make_sortkey(elem2)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function export.sort(elems, lang)&lt;br /&gt;
	local non_BMP&lt;br /&gt;
	for _, elem in ipairs(elems) do&lt;br /&gt;
		if contains_non_BMP(elem) then&lt;br /&gt;
			non_BMP = true&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return table.sort(elems, is_lang_object(lang) and export.make_compare_func(lang, non_BMP) or nil)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function export.sort_template(frame)&lt;br /&gt;
	if not mw.isSubsting() then&lt;br /&gt;
		error(&amp;quot;This template must be substed.&amp;quot;)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local args&lt;br /&gt;
	if frame.args.parent then&lt;br /&gt;
		args = frame:getParent().args&lt;br /&gt;
	else&lt;br /&gt;
		args = frame.args&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local elems = require(&amp;quot;Module:table&amp;quot;).shallowClone(args)&lt;br /&gt;
	local m_languages = require(&amp;quot;Module:languages&amp;quot;)&lt;br /&gt;
	local lang&lt;br /&gt;
	if args.lang then&lt;br /&gt;
		lang = m_languages.getByCode(args.lang) or m_languages.err(args.lang, &amp;#039;lang&amp;#039;)&lt;br /&gt;
	else&lt;br /&gt;
		local code = table.remove(elems, 1)&lt;br /&gt;
		code = code and mw.text.trim(code)&lt;br /&gt;
		lang = m_languages.getByCode(code) or m_languages.err(code, 1)&lt;br /&gt;
	end&lt;br /&gt;
	export.sort(elems, lang)&lt;br /&gt;
	return table.concat(elems, args.sep or &amp;quot;|&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return export&lt;/div&gt;</summary>
		<author><name>Chrysophylax</name></author>
	</entry>
</feed>