Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

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 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
  1. A string
  2. 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
  1. A base_string
  2. 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
  1. A string
  2. 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
  1. A string
  2. 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
  1. A string
≥ len
Conditional answer depending on string {1} length wrt {2}.
en:Template:Str ≥ len – internally: ge_len()
  1. A string
  2. A length
  3. Data to return/render when “longer than or equally long”.
  4. 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
  1. A string
  2. 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
  1. A string
  2. An offset
    Base 0: the first character is numbered 0, and so on.
  3. A length

Test page Bearbeiten

Available.

Functions for Lua modules (API) Bearbeiten

TEST(action,args)
Interface to unit tests.
  1. action
    string with function name
  2. args
    table; simulated template parameter list
Return string; like the legacy templates

Nowhere than by Vorlage:Str …… templates.

Dependencies Bearbeiten

None.