C# Class Tp.Core.Inflector

A class inspired by Ruby on Rails Inflector and Commons-Lang WordUtils.
Mostra file Open project: TargetProcess/Target-Process-Plugins

Public Methods

Method Description
Abbreviate ( this s, int maxWidth ) : string

Abbreviates a string using ellipses. This will turn "Now is the time for all good men" into "Now is the time for..."

Specifically:

    If s is less than maxWidth characters long, return it. Else abbreviate it to (substring(s, 0, max-3) + "..."). If maxWidth is less than 4, throw an ArgumentException. In no case will it return a string of length greater than maxWidth.
A null input string returns null. Abbreviate(null, 4) = null Abbreviate("", 4) = "" Abbreviate("abcdefg", 6) = "abc..." Abbreviate("abcdefg", 7) = "abcdefg" Abbreviate("abcdefg", 8) = "abcdefg" Abbreviate("abcdefg", 4) = "a..." Abbreviate("abcdefg", 3) = IllegalArgumentException
Brutalize ( this s ) : string

Anti-Humanize.

If you are curious where the name comes from, see Article for details.

Capitalize ( this s ) : string

Capitalizes all the whitespace separated words in a string.

A null input string returns null.

Humanize ( this s ) : string

Capitalizes the first word and turns underscores into spaces.

A null input string returns null.

Pluralize ( this s ) : string

Returns the plural form of the word in the string.

A null input string returns null. "post".Pluralize() => "posts" "octopus".Pluralize() => "octopi" "sheep".Pluralize() => "sheep" "words".Pluralize() => "words" "the blue mailman".Pluralize() => "the blue mailmen" "CamelOctopus".Pluralize() => "CamelOctopi"

Pluralize ( this s, int count ) : string
Singularize ( this s ) : string

The reverse of Pluralize(string), returns the singular form of a word in a string.

A null input string returns null. "posts".Singularize() => "post" "octopi".Singularize() => "octopus" "sheep".Singluarize() => "sheep" "word".Singluarize() => "word" "the blue mailmen".Singularize() => "the blue mailman" "CamelOctopi".Singularize() => "CamelOctopus"

Private Methods

Method Description
AddIrregularRule ( string singular, string plural ) : void
AddPluralRule ( string rule, string replacement ) : void

Adds the plural rule.

AddSingularRule ( string rule, string replacement ) : void
AddUnknownCountRule ( string word ) : void

Adds the unknown count rule.

ApplyRules ( IList rules, string word ) : string

Applies the rules.

Inflector ( ) : System

Initializes the Inflector class.

Method Details

Abbreviate() public static method

Abbreviates a string using ellipses. This will turn "Now is the time for all good men" into "Now is the time for..."
Specifically:
    If s is less than maxWidth characters long, return it. Else abbreviate it to (substring(s, 0, max-3) + "..."). If maxWidth is less than 4, throw an ArgumentException. In no case will it return a string of length greater than maxWidth.
A null input string returns null. Abbreviate(null, 4) = null Abbreviate("", 4) = "" Abbreviate("abcdefg", 6) = "abc..." Abbreviate("abcdefg", 7) = "abcdefg" Abbreviate("abcdefg", 8) = "abcdefg" Abbreviate("abcdefg", 4) = "a..." Abbreviate("abcdefg", 3) = IllegalArgumentException
public static Abbreviate ( this s, int maxWidth ) : string
s this
maxWidth int
return string

Brutalize() public static method

Anti-Humanize.
If you are curious where the name comes from, see Article for details.
public static Brutalize ( this s ) : string
s this
return string

Capitalize() public static method

Capitalizes all the whitespace separated words in a string.
A null input string returns null.
public static Capitalize ( this s ) : string
s this
return string

Humanize() public static method

Capitalizes the first word and turns underscores into spaces.
A null input string returns null.
public static Humanize ( this s ) : string
s this
return string

Pluralize() public static method

Returns the plural form of the word in the string.
A null input string returns null. "post".Pluralize() => "posts" "octopus".Pluralize() => "octopi" "sheep".Pluralize() => "sheep" "words".Pluralize() => "words" "the blue mailman".Pluralize() => "the blue mailmen" "CamelOctopus".Pluralize() => "CamelOctopi"
public static Pluralize ( this s ) : string
s this
return string

Pluralize() public static method

public static Pluralize ( this s, int count ) : string
s this
count int
return string

Singularize() public static method

The reverse of Pluralize(string), returns the singular form of a word in a string.
A null input string returns null. "posts".Singularize() => "post" "octopi".Singularize() => "octopus" "sheep".Singluarize() => "sheep" "word".Singluarize() => "word" "the blue mailmen".Singularize() => "the blue mailman" "CamelOctopi".Singularize() => "CamelOctopus"
public static Singularize ( this s ) : string
s this
return string