「モジュール:Wd」の版間の差分
ナビゲーションに移動
検索に移動
en:Module:Wd 2017年4月17日 (月) 11:47(UTC)より
template>K-iczn (en:Module:Wd 2017年3月19日 (日) 09:32(UTC)より) |
template>K-iczn (en:Module:Wd 2017年4月17日 (月) 11:47(UTC)より) |
||
150行目: | 150行目: | ||
end | end | ||
-- used to merge output | -- used to merge output arrays together; | ||
-- note that it currently mutates the first input | -- note that it currently mutates the first input array | ||
function | function mergeArrays(a1, a2) | ||
for i = 1, # | for i = 1, #a2 do | ||
a1[#a1 + 1] = a2[i] | |||
end | end | ||
return | return a1 | ||
end | end | ||
231行目: | 231行目: | ||
if i then | if i then | ||
-- year | -- year | ||
parts[index] = tonumber(mw.ustring.gsub(dateStr:sub(ptr, i-1), "^\+(.+)$", "%1"), 10) -- remove + sign | parts[index] = tonumber(mw.ustring.gsub(dateStr:sub(ptr, i-1), "^\+(.+)$", "%1"), 10) -- remove '+' sign (explicitly give base 10 to prevent error) | ||
if parts[index] == -0 then | if parts[index] == -0 then | ||
parts[index] = 0 | parts[index] = tonumber("0") -- for some reason, 'parts[index] = 0' may actually store '-0', so parse from string instead | ||
end | end | ||
526行目: | 526行目: | ||
sorted = ranks[1] | sorted = ranks[1] | ||
sorted = | sorted = mergeArrays(sorted, ranks[2]) | ||
sorted = | sorted = mergeArrays(sorted, ranks[3]) | ||
return sorted | return sorted | ||
817行目: | 817行目: | ||
if numDigits < 0 or numDigits == -0 then | if numDigits < 0 or numDigits == -0 then | ||
numDigits = 0 | numDigits = tonumber("0") -- for some reason, 'numDigits = 0' may actually store '-0', so parse from string instead | ||
end | end | ||
1,200行目: | 1,200行目: | ||
for i, v in ipairs(formatTable) do | for i, v in ipairs(formatTable) do | ||
if v.param then | if v.param then | ||
valuesArray = | valuesArray = mergeArrays(valuesArray, result[v.str]) | ||
else | else | ||
valuesArray[#valuesArray + 1] = {v.str} | valuesArray[#valuesArray + 1] = {v.str} | ||
1,206行目: | 1,206行目: | ||
if v.child then | if v.child then | ||
valuesArray = | valuesArray = mergeArrays(valuesArray, walk(v.child, result)) | ||
end | end | ||
end | end | ||
1,297行目: | 1,297行目: | ||
end | end | ||
out = | out = mergeArrays(out, result[parameters.qualifier..i]) | ||
end | end | ||
end | end | ||
1,628行目: | 1,628行目: | ||
if args["format"] then | if args["format"] then | ||
parsedFormat, formatParams = parseFormat(mw.text.trim(args["format"])) | parsedFormat, formatParams = parseFormat(mw.text.trim(args["format"])) | ||
elseif _.states.qualifiersCount > 0 then | elseif _.states.qualifiersCount > 0 then -- "qualifier(s)" command given | ||
if _.states[parameters.property] then | if _.states[parameters.property] then -- "propert(y|ies)" command given | ||
parsedFormat, formatParams = parseFormat(formats.propertyWithQualifier) | parsedFormat, formatParams = parseFormat(formats.propertyWithQualifier) | ||
else | else | ||
parsedFormat, formatParams = parseFormat(formats.qualifier) | parsedFormat, formatParams = parseFormat(formats.qualifier) | ||
end | end | ||
elseif _.states[parameters.property] then | elseif _.states[parameters.property] then -- "propert(y|ies)" command given | ||
parsedFormat, formatParams = parseFormat(formats.property) | parsedFormat, formatParams = parseFormat(formats.property) | ||
else | else -- "reference(s)" command given | ||
parsedFormat, formatParams = parseFormat(formats.reference) | parsedFormat, formatParams = parseFormat(formats.reference) | ||
end | |||
-- if a "qualifier(s)" command and no "propert(y|ies)" command has been given, make the movable separator a semicolon | |||
if _.states.qualifiersCount > 0 and not _.states[parameters.property] then | |||
_.separators["sep"..parameters.separator][1] = ";" | |||
end | |||
-- if only "reference(s)" has been given, make the emtpy string the default separator (except when raw) | |||
if _.states[parameters.reference] and not _.states[parameters.property] and _.states.qualifiersCount == 0 | |||
and not _.states[parameters.reference].rawValue then | |||
_.separators["sep"][1] = "" | |||
end | end | ||