Wikipedia:Lua/Modul/Vorlage:Str/en
Erscheinungsbild
Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
---|---|---|---|---|---|---|---|
Modul | Deutsch | English
|
Modul: | Dokumentation |
Vorlage:Str
– Module for support of the Vorlage:Str …… family, and do their entire work.
The collection is taken from the subset used in German Wikipedia in 2010.
Functions for templates
[Quelltext bearbeiten]As with the template implementation of 2006–2011, all string parameters will be trimmed (unregarded that all are unnamed).
- All parameters mentioned here are referring to the template transclusion, not
#invoke
call. #invoke
is to be called without any parameter.
- crop
- Used to remove the right-most {2} characters of a string {1}.
- en:Template:Str crop
- A string
- A length; 1 if omitted
- Throws error if {2} < 0
- Returns string; remaining starting characters, if any.
- find
- Position of first appearance of {2} in {1}.
- en:Template:Str find
- A base_string
- A sub_string
- Returns string;
-1
if sub_string not found - Character position is 1 based (not 0 based as usual in calculations).
- index
- Returns the {2}-th character of trimmed text {1}.
- en:Template:Str index
- A string
- A position, counted from 1 in string
- Throws error if {2} < 0 or {2} out of {1}
- left
- Gives the {2}-length substring of characters from the start of the trimmed string {1}.
- en:Template:Str left
- A string
- A length; if omitted, 1 is used
- Return the left {2} characters of {1}.
- If {2} is invalid, empty or zero, an empty string is returned.
- len
- Returns length of string (excluding spaces at the start and end).
- en:Template:Str len
- A string
- ≥ len
- Conditional answer depending on string {1} length wrt {2}.
- en:Template:Str ≥ len – internally:
ge_len()
- A string
- A length
- Data to return/render when “longer than or equally long”.
- Data to return/render when “shorter than”.
- Throws error if {1} undefined or invalid.
- Returns string; either {3} or {4}.
- right
- Gives the characters from {2} to the end of the string {1}.
- en:Template:Str right
- A string
- An offset
A negative offset is treated the same as zero, which simply returns the original string.
- sub
- Substring of string {1} starting at {2} and containing {3} chars.
- en:Template:Str sub old
- A string
- An offset
Base 0: the first character is numbered 0, and so on. - A length
Test page
[Quelltext bearbeiten]Functions for Lua modules (API)
[Quelltext bearbeiten]- TEST(action,args)
- Interface to unit tests.
- action
string with function name - args
table; simulated template parameter list
- action
- Return string; like the legacy templates
Usage
[Quelltext bearbeiten]Nowhere than by Vorlage:Str …… templates.
Dependencies
[Quelltext bearbeiten]None.