Module:String2/doc: Difference between revisions

Content deleted Content added
fix link
Remove documentation mentioning upper and lower.
Line 4:
The module '''String2''' contains a number of string manipulation functions that are much less commonly used than those in [[Module:String]]. Because Module:String is cascade-protected (some of its functions are used on the Main Page), it cannot be edited or maintained by template editors, only by admins. While it is true that string-handling functions rarely need maintenance, it is useful to allow that by template editors where possible, so this module may be used by template editors to develop novel functionality.
 
The module contains fivethree case-related calls that convert strings to upper,first lowerletter uppercase, sentence case or title case and two calls that are useful for working with substrings. There are other utility calls that strip leading zeros from padded numbers and transform text so that it is not interpreted as wikitext, and several other calls that solve specific problems for template developers such as finding the position of a piece of text on a given page.
 
The functions are designed with the possibility of working with text returned from Wikidata in mind. However, a call to Wikidata may return empty, so the functions should generally fail gracefully if supplied with a missing or blank input parameter, rather than throwing an error.
Line 13:
 
=== upper ===
Do not useRemoved: use {{magic word|uc:}} which handles [[mw:strip markers|strip markers]] correctly.
 
=== lower ===
Do not useRemoved: use {{magic word|lc:}} which handles [[mw:strip markers|strip markers]] correctly.
 
=== title ===
Line 28:
 
=== ucfirst ===
The ucfirst function is similar to sentence; it renders the first alphabetical character in upper case, but leaves the capitalisation of the rest of the text unaltered. This is useful if the text contains proper nouns, but it will not regularise sentences that are ALLCAPS, for example. It also works with text containing piped wiki-links and with html lists. <s><code>label</code> is an alias to this function for backward compatibility.</s>(now obseleteobsolete)
 
=== findlast ===
Line 134:
== Usage ==
 
* <code><nowiki>{{#invoke:String2 | upper |…}}</nowiki></code> - Shifts all characters to uppercase
* <code><nowiki>{{#invoke:String2 | lower |…}}</nowiki></code> - Shifts all characters to lowercase
* <code><nowiki>{{#invoke:String2 | sentence |…}}</nowiki></code> - Capitalizes the first character and shifts the rest to lowercase
** Although similar to [[Help:Magic_words#Formatting|magic words]]' <code><nowiki>{{ucfirst:}}</nowiki></code> function, this call works even with piped wiki-links because it searches beyond leading brackets and other non-alphanumeric characters.
Line 147 ⟶ 145:
=== Parameters ===
These functions take one unnamed parameter comprising (or invoking as a string) the text to be manipulated:
* upper
* lower
* title
* sentence
Line 158 ⟶ 154:
! scope="col" | Input
! scope="col" | Output
|-
| <nowiki>{{#invoke:String2| upper | abcd }}</nowiki>
| {{#invoke:String2| upper | abcd }}
|-
| <nowiki>{{#invoke:String2| upper | abCD }}</nowiki>
| {{#invoke:String2| upper | abCD }}
|-
| <nowiki>{{#invoke:String2| upper | ABcd }}</nowiki>
| {{#invoke:String2| upper | ABcd }}
|-
| <nowiki>{{#invoke:String2| upper | ABCD }}</nowiki>
| {{#invoke:String2| upper | ABCD }}
|-
| <nowiki>{{#invoke:String2| upper | }}</nowiki>
| {{#invoke:String2| upper | }}
|-
| &nbsp;
|
|-
| <nowiki>{{#invoke:String2| lower | abcd }}</nowiki>
| {{#invoke:String2| lower | abcd }}
|-
| <nowiki>{{#invoke:String2| lower | abCD }}</nowiki>
| {{#invoke:String2| lower | abCD }}
|-
| <nowiki>{{#invoke:String2| lower | ABcd }}</nowiki>
| {{#invoke:String2| lower | ABcd }}
|-
| <nowiki>{{#invoke:String2| lower | ABCD }}</nowiki>
| {{#invoke:String2| lower | ABCD }}
|-
| <nowiki>{{#invoke:String2| lower | }}</nowiki>
| {{#invoke:String2| lower | }}
|-
| &nbsp;
|
|-
| <nowiki>{{#invoke:String2| ucfirst | abcd }}</nowiki>