Toggle menu
15
236
75
27.7K
Kenshi Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 04:17, 8 March 2025 by Prd (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
return {
	singles = {

	},
	ranges = {

	},
	aliases = {
		[ "1.1"] = "V1_1",
		[ "2.0"] = "V2_0",
		[ "2.1"] = "V2_1",
		[ "3.0"] = "V3_0",
		[ "3.1"] = "V3_1",
		[ "3.2"] = "V3_2",
		[ "4.0"] = "V4_0",
		[ "4.1"] = "V4_1",
		[ "5.0"] = "V5_0",
		[ "5.1"] = "V5_1",
		[ "5.2"] = "V5_2",
		[ "6.0"] = "V6_0",
		[ "6.1"] = "V6_1",
		[ "6.2"] = "V6_2",
		[ "6.3"] = "V6_3",
		[ "7.0"] = "V7_0",
		[ "8.0"] = "V8_0",
		[ "9.0"] = "V9_0",
		["10.0"] = "V10_0",
		["11.0"] = "V11_0",
		["12.0"] = "V12_0",
		["12.1"] = "V12_1",
		["13.0"] = "V13_0",
		["14.0"] = "V14_0",
		[  "NA"] = "Unassigned",
	},
}

local p = {}

function p.main(frame)
	local page = frame.args[1] or "User:Prd/Unicode/DerivedCoreProperties.txt"
	local text = assert(mw.title.new(page):getContent())
	local singles, ranges = {}, {}
	for code_point1, code_point2, age in text:gmatch("%f[^\n%z](%x+)%.?%.?(%x*)%s*;%s*([%d.]+)") do
		code_point1, code_point2 = tonumber(code_point1, 16), tonumber(code_point2, 16)
		local last_range = ranges[#ranges]
		if last_range and last_range[2] == code_point1 - 1 and last_range[3] == age then
			last_range[2] = code_point2 or code_point1
		elseif singles[code_point1 - 1] == age then
			singles[code_point1 - 1] = nil
			table.insert(ranges, { code_point1 - 1, code_point2 or code_point1, age })
		else
			if not code_point2 then
				singles[code_point1] = age
			else
				table.insert(ranges, { code_point1, code_point2, age })
			end
		end
	end
	
		local template = [[
return {
	singles = {
...
	},
	ranges = {
...
	},
	aliases = {
...
	},
}
]]

	table.sort(
		ranges,
		function(range1, range2)
			return range1[1] < range2[1]
		end)
	
	local function make_padding(age)
		return (" "):rep(#'"12.1"' - (#age + 2))
	end
	
	local Array = require "Module:array"
	local printed_ranges = Array()
	for _, range in ipairs(ranges) do
		local low, high, age = unpack(range)
		printed_ranges:insert(('\t\t{ 0x%06X, 0x%06X, %s%q },')
			:format(low, high, make_padding(age), age))
	end
	
	local printed_singles = Array()
	for codepoint, age in require 'Module:TableTools'.sortedPairs(singles) do
		printed_singles:insert(('\t\t[0x%06X] = %s%q,')
			:format(codepoint, make_padding(age), age))
	end
	
	local printed_aliases = Array()
	local property_value_aliases = mw.title.new "User:Prd/Unicode/PropertyValueAliases.txt":getContent()
	local age_aliases = property_value_aliases:match "# Age[^\n]+%s*(.-)%s*%f[^\n]#"
	for age, alias in age_aliases:gmatch "age%s*;%s*(%S+)%s*;%s*(%S+)" do
		printed_aliases:insert(('\t\t[%s"%s"] = "%s",')
			:format(make_padding(age), age, alias))
	end
	
	local data = template
		:gsub('%.%.%.', printed_singles:concat('\n'), 1)
		:gsub('%.%.%.', printed_ranges:concat('\n'), 1)
		:gsub('%.%.%.', printed_aliases:concat('\n'), 1)
	
	return mw.getCurrentFrame():extensionTag{
		name = "syntaxhighlight",
		content = data,
		args = { lang = "lua" }
	}
end

return p