-- lx format
local format = require("core.format")

-- MD5 is always 32 hexadecimal digits
local digest_pattern = string.rep("%x", 32)

format.register({
	name = "MD5 Checksums",
	shortname = "MD5",
	author = "liqube",

	extensions = {
		"md5",
		"md5sums",
	},
	filenames = {
		"MD5SUMS",
		"MD5SUMS.txt",
	},
	-- First complete checksum record
	headers = "^" .. digest_pattern .. " [ *][^\r\n]+",

	patterns = {
		-- Optional manifest comments
		{ pattern = "#.-\n", type = "comment", line_start = true },

		-- Exact digest, separator/mode, filename
		{
			pattern = "(" .. digest_pattern .. ")( [ %*])([^\r\n]+)",
			type = { "hex", "operator", "normal" },
			line_start = true,
		},
	},
})
