Module:Thai-sortkey
Appearance
- The following documentation is located at Module:Thai-sortkey/documentation. [edit] Categories were auto-generated by Module:module categorization. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will sort text in the Thai script. It is used to sort Eastern Bru, Western Bru, Bisu, Nyah Kur, Chong, Khün, Western Lawa, Eastern Lawa, Kedah Malay, Pattani Malay, Northern Thai, Nyaw, Sanskrit, Saek, Southern Thai, Thai, Thavung, Isan, Gong, Urak Lawoi', and Yong.
The module should preferably not be called directly from templates or other modules.
To use it from a template, use {{sortkey}}.
Within a module, use Module:languages#Language:makeSortKey.
For testcases, see Module:Thai-sortkey/testcases.
Functions
makeSortKey(text, lang, sc)- Generates a sortkey for a given piece of
textwritten in the script specified by the codesc, and language specified by the codelang. - When the sort fails, returns
nil.
local export = {}
local m_str_utils = require("Module:string utilities")
local gmatch = m_str_utils.gmatch
local gsub = m_str_utils.gsub
local u = m_str_utils.char
local minorMarkSet = "([" .. u(0xE47) .. "-" .. u(0xE4E) .. u(0x302) .. u(0x304) .. u(0x331) .. "])"
local minorMarks = {
[u(0xE47)] = "0", [u(0xE48)] = "1", [u(0xE49)] = "2", [u(0xE4A)] = "3", [u(0xE4B)] = "4",
[u(0xE4C)] = "5", [u(0xE4D)] = "6", [u(0xE4E)] = "7", [u(0x302)] = "8", [u(0x304)] = "9", [u(0x331)] = "A"
}
function export.makeSortKey(text, lang, sc)
local minorKey = ""
for mark in gmatch(text, minorMarkSet) do
minorKey = minorKey .. minorMarks[mark]
end
text = gsub(text, minorMarkSet, "")
text = gsub(text, "[%pๆ]", "")
text = gsub(text, "([เแโใไ])(ʼ?[ก-ฮ])", "%2%1")
return text .. minorKey
end
-- compare between Thai texts
function export.string_compare(item1, item2)
return export.makeSortKey(item1) < export.makeSortKey(item2)
end
return export
Categories:
- Thai script
- Sortkey-generating modules by script
- Thai script modules
- Sortkey-generating modules
- Pattani Malay modules
- Isan modules
- Saek modules
- Thavung modules
- Southern Thai modules
- Khün modules
- Western Lawa modules
- Nyah Kur modules
- Chong modules
- Western Bru modules
- Kedah Malay modules
- Nyaw modules
- Gong modules
- Eastern Lawa modules
- Yong modules
- Northern Thai modules
- Bisu modules
- Urak Lawoi' modules
- Thai modules
- Sanskrit modules
- Eastern Bru modules