Module:Str rightc
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This Lua module is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
This implements: {{str rightc}} but if |notemplate= is set to a non-empty string, arguments from the invocation can be used.
Usage
{{#invoke:str rightc|rightc|notemplate=1|string|count}}{{#invoke:str rightc|rightc|notemplate=1|string|count|result if empty}}
Gives a substring of length count characters from the right-side end of the string, or, if provided, returns result if empty when string is empty.
Examples
{{#invoke:str rightc|rightc|notemplate=1 |Lorem ipsum dolor sit amet |10}}→ r sit amet{{#invoke:str rightc|rightc|notemplate=1 |Lorem ipsum dolor sit amet |1}}→ t{{#invoke:str rightc|rightc|notemplate=1 |Lorem ipsum dolor sit amet |0}}→{{#invoke:str rightc|rightc|notemplate=1 | |1 |string is empty}}→ string is empty{{#invoke:str rightc|rightc|notemplate=1 |123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-1 |99}}→ 3456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-1
require[[strict]]
local p = {}
function p._rightc(str, count, empty)
str = mw.text.trim(str or '')
if '' == str then
return mw.text.trim(empty or '')
end
count = tonumber(count or '')
if nil == count then
return str
end
if count <= 0 then
return ''
end
return mw.ustring.sub(str, -count)
end
function p.rightc(frame)
local args = frame.args
if '' == (args.notemplate or '') then
args = frame:getParent().args
end
return p._rightc(args[1], args[2], args[3])
end
return p