Jump to content

Module:Str rightc

From Elite Dangerous Wiki
Revision as of 12:27, 22 June 2026 by Wikipedia>MSGJ (Protected "Module:Str rightc": High-risk template or module: used in interface messages ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite)))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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