Template:Class plural/doc

This template returns the plural form of a given class name. Some names are both singular and plural, some are spelled differently (e.g. thief and thieves). The case of the name is preserved.

Examples:
 * returns.
 * returns.
 * returns.
 * returns.

Under the Hood
Here is a sample of the template code, with line breaks for readability:

If the template were called like this: Then the input to the template and the value of  is "Thief ". Note that leading whitespaces are ignored. The  function finds the length of a string ignoring any trailing whitespace, so   returns. The substring function,  extracts the substring starting at index 0 for a given length, so   becomes "Thief" with no leading or trailing whitespace. Finally, "Thief" is assigned to the variable single to be used later. From now on,  will be replaced with "Thief".

Next we save the first character in the variable fc using   (index of 0, length of 1). If the input to the template is "Thief ", then the value of fc will be "T".

The  function returns a lower-case version, so "Thief" becomes "thief". Then the  statement compares "thief" with its list of cases, looking for a match. Near the bottom of the list it finds "thief" and returns the value of, which is the preserved first letter "T" and the appended string "hieves" to form "Thieves", which is returned as the result of the template.

If a word is both singular and plural, then just return it (e.g., "Samurai" returns "Samurai"). If the argument is not found in the list of cases, then the  case is used to just put an 's' on the end of the word and return it.

The illustration above put line breaks between the first three lines for readability, but in the actual template code, any whitespace or line breaks between the "includeonly" tags will show up in the output.