Differenze tra le versioni di "Modulo:Wikilib/forms"

Better support for alt forms without ndex in ndex *** sovrascritto il testo esistente ***
(Internal updates *** sovrascritto il testo esistente ***)
(Better support for alt forms without ndex in ndex *** sovrascritto il testo esistente ***)
 
 
--]]
---@deprecated use getndexabbr instead
f.getnameabbr = function(name, extform)
if alt[tonumber(name) or name:lower()] then
return tonumber(poke) or poke or "", abbr or "base"
end
---@deprecated use getndexabbr instead
f.getNameAbbr = f.getnameabbr
 
The name behaviour is needed because in general it not possible to separate the
name from the abbr. If there is some extra assumption (eg. the name is all
lowercase), itsit's the caller's resposibility to exploit it.)
 
--]]
end
 
--[[
 
Given a key of Poké-data (or other data modules), split the ndex/name from the
abbr.
 
WARNING: don't use this function for user input; use getndexabbr instead and
force split name and abbr parameters.
 
Note: in general it is not possible to separate the name from the abbr. To do
so, this function assumes that the Pokémon name is all lowercase, and the abbr
start with the first uppercase letter. Note that for user input this is not
always the case (eg. the argument is composed using name and abbr parameters of
a template). However, this works if the input is a key in Poké-data.
 
--]]
---@param name string An ndex/name+abbr or Pokémon name
---@return number|string, string
f.getpokekeyabbr = function(name)
-- name is just an ndex
local ndex = string.match(name, "^(%d+)$")
if ndex then
return tonumber(ndex), "base" ---@diagnostic disable-line: return-type-mismatch
end
-- name is an ndex followed by an abbr
local ndex, abbr_ = string.match(name, "^(%d+)(%u%a*)$")
if ndex then
return tonumber(ndex), abbr_ ---@diagnostic disable-line: return-type-mismatch
end
-- name is not an ndex, so split on the first uppercase letter
if string.match(name, "%u") then
return string.match(name, "^(%U*)(%u%a*)$")
else
return name, "base"
end
end
--[[
 
79 548

contributi