This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Converts the specified string to title case. | |
/// </summary> | |
/// <remarks> | |
/// This functionality is based off John Gruber's title case function, described at http://daringfireball.net/2008/05/title_case. | |
/// | |
/// It capitalizes each word in the specified string, with the following exceptions: | |
/// <list type="bullet"> | |
/// <item><description>Some words are not capitalized, such as "for" and "the".</description></item> | |
/// <item><description>Words with capitalized letters other than the first, words containing dots and words containing numbers are left unchanged.</description></item> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Attempts to pluralize the specified text according to the rules of the English language. | |
/// </summary> | |
/// <remarks> | |
/// This function attempts to pluralize as many words as practical by following these rules: | |
/// <list type="bullet"> | |
/// <item><description>Words that don't follow any rules (e.g. "mouse" becomes "mice") are returned from a dictionary.</description></item> | |
/// <item><description>Words that end with "y" (but not with a vowel preceding the y) are pluralized by replacing the "y" with "ies".</description></item> | |
/// <item><description>Words that end with "us", "ss", "x", "ch" or "sh" are pluralized by adding "es" to the end of the text.</description></item> | |
/// <item><description>Words that end with "f" or "fe" are pluralized by replacing the "f(e)" with "ves".</description></item> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void TestEasyNouns() | |
{ | |
// Easy (i.e. they follow rules) nouns culled from http://www.manythings.org/vocabulary/lists/l/words.php?f=ogden-general_things | |
Assert.AreEqual("accounts", StringHelper.Pluralize("account")); | |
Assert.AreEqual("acts", StringHelper.Pluralize("act")); | |
Assert.AreEqual("additions", StringHelper.Pluralize("addition")); | |
Assert.AreEqual("adjustments", StringHelper.Pluralize("adjustment")); | |
Assert.AreEqual("advertisements", StringHelper.Pluralize("advertisement")); | |
Assert.AreEqual("agreements", StringHelper.Pluralize("agreement")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void TestTitleCases() | |
{ | |
// From https://github.com/ap/titlecase/blob/master/test.pl | |
Assert.AreEqual("For Step-by-Step Directions Email someone@gmail.com", StringHelper.ToTitleCase("For step-by-step directions email someone@gmail.com")); | |
Assert.AreEqual("2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'", StringHelper.ToTitleCase("2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'")); | |
Assert.AreEqual("Have You Read “The Lottery”?", StringHelper.ToTitleCase("Have you read “The Lottery”?")); | |
Assert.AreEqual("Your Hair[cut] Looks (Nice)", StringHelper.ToTitleCase("your hair[cut] looks (nice)")); | |
Assert.AreEqual("People Probably Won't Put http://foo.com/bar/ in Titles", StringHelper.ToTitleCase("People probably won't put http://foo.com/bar/ in titles")); | |
// NOTE: Replaced the original non-breaking hyphens with regular hyphens |