...

Source file src/github.com/gobuffalo/flect/name/name.go

Documentation: github.com/gobuffalo/flect/name

     1  package name
     2  
     3  import (
     4  	"encoding"
     5  	"strings"
     6  
     7  	"github.com/gobuffalo/flect"
     8  )
     9  
    10  // Proper pascalizes and singularizes the string
    11  //	person = Person
    12  //	foo_bar = FooBar
    13  //	admin/widgets = AdminWidget
    14  func Proper(s string) string {
    15  	return New(s).Proper().String()
    16  }
    17  
    18  // Proper pascalizes and singularizes the string
    19  //	person = Person
    20  //	foo_bar = FooBar
    21  //	admin/widgets = AdminWidget
    22  func (i Ident) Proper() Ident {
    23  	return Ident{i.Singularize().Pascalize()}
    24  }
    25  
    26  // Group pascalizes and pluralizes the string
    27  //	person = People
    28  //	foo_bar = FooBars
    29  //	admin/widget = AdminWidgets
    30  func Group(s string) string {
    31  	return New(s).Group().String()
    32  }
    33  
    34  // Group pascalizes and pluralizes the string
    35  //	person = People
    36  //	foo_bar = FooBars
    37  //	admin/widget = AdminWidgets
    38  func (i Ident) Group() Ident {
    39  	var parts []string
    40  	if len(i.Original) == 0 {
    41  		return i
    42  	}
    43  	last := i.Parts[len(i.Parts)-1]
    44  	for _, part := range i.Parts[:len(i.Parts)-1] {
    45  		parts = append(parts, flect.Pascalize(part))
    46  	}
    47  	last = New(last).Pluralize().Pascalize().String()
    48  	parts = append(parts, last)
    49  	return New(strings.Join(parts, ""))
    50  }
    51  
    52  var _ encoding.TextUnmarshaler = &Ident{}
    53  var _ encoding.TextMarshaler = &Ident{}
    54  
    55  func (i *Ident) UnmarshalText(data []byte) error {
    56  	(*i) = New(string(data))
    57  	return nil
    58  }
    59  
    60  func (i Ident) MarshalText() ([]byte, error) {
    61  	return []byte(i.Original), nil
    62  }
    63  

View as plain text