Module:Person height
Appearance
This Lua module is used onapproximately 269,000 pages. To avoid major disruption and server load, any changes should be tested in the module's/sandboxor/testcasessubpages, or in your ownmodule sandbox.The tested changes can be added to this page in a single edit. Consider discussing changes on thetalk pagebefore implementing them. |
This module is rated asbeta,and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
Usage
Intended for use in infoboxes;{{#invoke:person height|main|5ft 6in}}
→ 5 ft 6 in (168 cm). SeeTemplate:Infobox person/heightfor details.
See also
-- This module implements [[Template:Infobox person/height]]
localp={}
localfunctionsplitsuffix(s)
localsuffix=''
ifmw.ustring.match(s,'^(.-)(<sup.*)$')then
locala=mw.ustring.gsub(s,'^(.-)(<sup.*)$','%1')
localb=mw.ustring.gsub(s,'^(.-)(<sup.*)$','%2')
s=a
suffix=b..suffix
end
ifmw.ustring.match(s,'^(.-)(%[%[[Cc]ategory:.*)$')then
locala=mw.ustring.gsub(s,'^(.-)(%[%[[Cc]ategory:.*)$','%1')
localb=mw.ustring.gsub(s,'^(.-)(%[%[[Cc]ategory:.*)$','%2')
s=a
suffix=b..suffix
end
returns,suffix
end
localfunctionclean(s)
s=mw.ustring.gsub(s,'[Mm]etre','m')
s=mw.ustring.gsub(s,'([^a])meter','%1m')-- prevents "parameter" from being changed to "param"
s=mw.ustring.gsub(s,'[Cc]enti','c')-- changes "centim" to "cm"
s=mw.ustring.gsub(s,'ms','m')
s=mw.ustring.gsub(s,'m[%.,]','m')
s=mw.ustring.gsub(s,'[Ff]eet','ft')
s=mw.ustring.gsub(s,'foot','ft')
s=mw.ustring.gsub(s,'ft[%.,]','ft')
s=mw.ustring.gsub(s,'[Ii]nches','in')
s=mw.ustring.gsub(s,'[Ii]nch','in')
s=mw.ustring.gsub(s,'ins','in')
s=mw.ustring.gsub(s,'in[%.,]','in')
s=mw.ustring.gsub(s,'%[%[[Mm]%]%]s','[[Metre|m]]')
s=mw.ustring.gsub(s,'%[%[[Mm]|[Mm]%]%]','[[Metre|m]]')
s=mw.ustring.gsub(s,'%[%[[Cc]m%]%]s','[[Centimetre|cm]]')
s=mw.ustring.gsub(s,'%[%[[Cc]m|[Cc]m%]%]','[[Centimetre|cm]]')
s=mw.ustring.gsub(s,'%[%[[Cc]entim|cm%]%]','[[Centimetre|cm]]')
s=mw.ustring.gsub(s,'%[%[[Ii]n|in%]%]','[[inch|in]]')
s=mw.ustring.gsub(s,'(%d)%s+[Cc][Mm]','%1 cm')
s=mw.ustring.gsub(s,'(%d)%s+[Mm]','%1 m')
s=mw.ustring.gsub(s,'(%d)%s+[Ff][Tt]','%1 ft')
s=mw.ustring.gsub(s,'(%d)%s+[Ii][Nn]','%1 in')
s=mw.ustring.gsub(s,'(%d&[Nn][Bb][Ss][Pp];)[Cc][Mm]','%1cm')
s=mw.ustring.gsub(s,'(%d&[Nn][Bb][Ss][Pp];)[Mm]','%1m')
s=mw.ustring.gsub(s,'(%d&[Nn][Bb][Ss][Pp];)[Ff][Tt]','%1ft')
s=mw.ustring.gsub(s,'(%d&[Nn][Bb][Ss][Pp];)[Ii][Nn]','%1in')
s=mw.ustring.gsub(s,'(%d)%s*[′\']%s*([%d]%d*)%s*[\ "″]','%1 ft %2 in')
returns
end
localfunctionisnumber(s)
ifsthen
s=mw.ustring.gsub(s,'%+%s*%d+%s*/%s*%d+%s*$','')
s=mw.ustring.gsub(s,'%s*1%s*/%s*2%s*$','0.5')
returntonumber(s)
end
returnnil
end
localfunctiontrimspace(s)
ifsthen
s=mw.ustring.gsub(s,'^%s*(.-)%s*$','%1')
end
returns
end
localfunctionforce_unit(s,t)
s=mw.ustring.gsub(s,'&[Nn][Bb][Ss][Pp];','★')
if(t=='cm')then
s=mw.ustring.gsub(s,'(%d*)%.(%d%d)(%d+[★%s]+)m','%1%2.%3cm')
s=mw.ustring.gsub(s,'(%d*)%.(%d%d)(%d+[★%s]+)%[%[[Mm]et[re][re]|m%]%]','%1%2.%3[[centimetre|cm]]')
s=mw.ustring.gsub(s,'(%d*)%.(%d%d)([★%s]+)m','%1%2%3cm')
s=mw.ustring.gsub(s,'(%d*)%.(%d%d)([★%s]+)%[%[[Mm]et[re][re]|m%]%]','%1%2%3[[centimetre|cm]]')
s=mw.ustring.gsub(s,'(%d*)%.(%d)([★%s]+)m','%1%20%3cm')
s=mw.ustring.gsub(s,'(%d*)%.(%d)([★%s]+)%[%[[Mm]et[re][re]|m%]%]','%1%20%3[[centimetre|cm]]')
s=mw.ustring.gsub(s,'(%d*)%.([★%s]+)m','%100.%2cm')
s=mw.ustring.gsub(s,'(%d*)%.([★%s]+)%[%[[Mm]et[re][re]|m%]%]','%100.%2[[centimetre|cm]]')
s=mw.ustring.gsub(s,'^(%s*%d+)([★%s]+)m','%100%2cm')
s=mw.ustring.gsub(s,'([%(★%s]%d+)([★%s]+)m','%100%2cm')
s=mw.ustring.gsub(s,'^(%s*%d+)([★%s]+)%[%[[Mm]et[re][re]|m%]%]','%100%2[[centimetre|cm]]')
s=mw.ustring.gsub(s,'([%(★%s]%d+)([★%s]+)%[%[[Mm]et[re][re]|m%]%]','%100%2[[centimetre|cm]]')
s=mw.ustring.gsub(s,'0(%d+%.?%d*[★%s]+cm)','%1')
s=mw.ustring.gsub(s,'0(%d+%.?%d*[★%s]+%[%[[Cc]entimet[re][re]|cm%]%])','%1')
else
s=mw.ustring.gsub(s,'(%d)(%d%d)%.(%d*[★%s]+)cm','%1.%2%3m')
s=mw.ustring.gsub(s,'(%d)(%d%d)%.(%d*[★%s]+)%[%[[Cc]entimet[re][re]|cm%]%]','%1.%2%3[[metre|m]]')
s=mw.ustring.gsub(s,'(%d)(%d%d)([★%s]+)cm','%1.%2%3m')
s=mw.ustring.gsub(s,'(%d)(%d%d)([★%s]+)%[%[[Cc]entimet[re][re]|cm%]%]','%1.%2%3[[metre|m]]')
s=mw.ustring.gsub(s,'(%d%d)%.(%d*[★%s]+)cm','0.%1%2m')
s=mw.ustring.gsub(s,'(%d%d)%.(%d*[★%s]+)%[%[[Cc]entimet[re][re]|cm%]%]','0.%1%2[[metre|m]]')
s=mw.ustring.gsub(s,'(%d%d)([★%s]+)cm','0.%1%2m')
s=mw.ustring.gsub(s,'(%d%d)([★%s]+)%[%[[Cc]entimet[re][re]|cm%]%]','0.%1%2[[metre|m]]')
end
s=mw.ustring.gsub(s,'★',' ')
returns
end
localfunctionget_convert_args(s,prefer,enforce,ri)
localprefer_m=(preferor'')=='m'
localforce_m=(enforceor'')=='m'
localprefer_cm=(preferor'')=='cm'
localforce_cm=(enforceor'')=='cm'
ri=(rior'')=='cmin'and'cmin'or''
unconverted=clean(sor'')-- basic unit cleaning
s=mw.ustring.gsub(unconverted,'&[Nn][Bb][Ss][Pp];',' ')
localm=mw.ustring.find(s,'m')
localc=mw.ustring.find(s,'cm')
localf=mw.ustring.find(s,'ft')
locali=mw.ustring.find(s,'in')
ifm==nilandf==nilandi==nilthen
return'',unconverted
end
localadj=nil
ifc~=nilandf==nilandi==nilthen
localn=mw.ustring.sub(s,1,c-1)
ifisnumber(n)then
ifforce_mthen
localprec=require("Module:Math")._precision(trimspace(n))
adj=(prec==1)and'ri3'or'ri2'
end
ifri~=''then
adj=force_mand'ri2'or'ri0'
end
returnforce_m
and{n/100,'m','ftin',0,['abbr']='on',['adj']=adj}
or{n,'cm','ftin',0,['abbr']='on',['adj']=adj},mw.ustring.sub(s,c+2)
end
return'',unconverted
end
ifm~=nilandc==nilandf==nilandi==nilthen
localn=mw.ustring.sub(s,1,m-1)
ifri~=''then
adj=force_cmand'ri0'or'ri2'
end
ifisnumber(n)then
returnforce_cm
and{n*100,'cm','ftin',0,['abbr']='on',['adj']=adj}
or{n,'m','ftin',0,['abbr']='on',['adj']=adj},mw.ustring.sub(s,m+1)
end
return'',unconverted
end
iff~=nilandi~=nilandm==nilthen
localn1=mw.ustring.sub(s,1,f-1)
localn2=mw.ustring.sub(s,f+2,i-1)
ifisnumber(n1)andisnumber(n2)then
ifri~=''then
adj='ri0'
end
return(force_morprefer_m)
and{n1,'ft',n2,'in','m',2,['abbr']='on',['adj']=adj}
or{n1,'ft',n2,'in','cm',0,['abbr']='on',['adj']=adj},mw.ustring.sub(s,i+2)
end
return'',unconverted
end
iff~=nilandi==nilandm==nilthen
localn=mw.ustring.sub(s,1,f-1)
ifisnumber(n)then
ifri~=''then
localn2=12*(n-math.floor(n))
adj='ri0'
return(force_morprefer_m)
and{math.floor(n),'ft',n2,'in','m',2,['abbr']='on',['adj']=adj}
or{math.floor(n),'ft',n2,'in','cm',0,['abbr']='on',['adj']=adj},mw.ustring.sub(s,f+2)
end
return(force_morprefer_m)
and{n,'ft','m',2,['abbr']='on'}
or{n,'ft','cm',0,['abbr']='on'},mw.ustring.sub(s,f+2)
end
return'',unconverted
end
ifi~=nilandf==nilandm==nilthen
localn=mw.ustring.sub(s,1,i-1)
ifisnumber(n)then
ifri~=''then
adj='ri0'
end
return(force_morprefer_m)
and{n,'in','m',2,['abbr']='on'}
or{n,'in','cm',0,['abbr']='on'},mw.ustring.sub(s,i+2)
end
return'',unconverted
end
ifforce_cmandc==nilthen
return'',force_unit(unconverted,'cm')
end
ifforce_mandc~=nilthen
return'',force_unit(unconverted,'m')
end
return'',unconverted
end
functionconvert(frame,args)
localstr,suffix=splitsuffix(args[1]or'')
localtargs,str=get_convert_args(str,args['prefer']or'',args['enforce']or'',args['ri']or'')
str=str..suffix
iftype(targs)=='table'then
returnframe:expandTemplate{title='convert',args=targs}..str
else
returnstr
end
end
functionp.main(frame)
returnconvert(frame,frame.args[1]andframe.argsorframe:getParent().args)
end
returnp