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, but if they ever come up with a multi-word class name that requires an alternate spelling (other than adding an 's' suffix) then some more logic will have to be added.

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

Under the Hood
Here is what the template looks like as of this writing, with a line break 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".

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. The substring function in this case takes the first character (index of 0, length of 1) of, which is "T", and appends "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 a line break between the first two lines for readability, but in the actual template code, any whitespace or line breaks between the "includeonly" tags will show up in the output.