prose: github.com/jdkato/prose/transform Index | Examples | Files

package transform

import "github.com/jdkato/prose/transform"

Package transform implements functions to manipulate UTF-8 encoded strings.

Index

Examples

Package Files

title.go transform.go

func Camel Uses

func Camel(s string) string

Camel returns a Camel-cased copy of the string s.

Code:

fmt.Println(Camel("test string"))

Output:

testString

func Constant Uses

func Constant(s string) string

Constant returns a underscore-separated, upper-cased copy of the string s.

Code:

fmt.Println(Constant("test string"))

Output:

TEST_STRING

func Dash Uses

func Dash(s string) string

Dash returns a dash-separated, lower-cased copy of the string s.

Code:

fmt.Println(Dash("test string"))

Output:

test-string

func Dot Uses

func Dot(s string) string

Dot returns a period-separated, lower-cased copy of the string s.

Code:

fmt.Println(Dot("test string"))

Output:

test.string

func Pascal Uses

func Pascal(s string) string

Pascal returns a Pascal-cased copy of the string s.

Code:

fmt.Println(Pascal("test string"))

Output:

TestString

func Simple Uses

func Simple(s string) string

Simple returns a space-separated, lower-cased copy of the string s.

Code:

fmt.Println(Simple("test string"))

Output:

test string

func Snake Uses

func Snake(s string) string

Snake returns a underscore-separated, lower-cased copy of the string s.

Code:

fmt.Println(Snake("test string"))

Output:

test_string

type IgnoreFunc Uses

type IgnoreFunc func(word string, firstOrLast bool) bool

An IgnoreFunc is a TitleConverter callback that decides whether or not the the string word should be capitalized. firstOrLast indicates whether or not word is the first or last word in the given string.

var (
    // APStyle states to:
    // 1. Capitalize the principal words, including prepositions and
    //    conjunctions of four or more letters.
    // 2. Capitalize an article – the, a, an – or words of fewer than four
    //    letters if it is the first or last word in a title.
    APStyle IgnoreFunc = optionsAP

    // ChicagoStyle states to lowercase articles (a, an, the), coordinating
    // conjunctions (and, but, or, for, nor), and prepositions, regardless of
    // length, unless they are the first or last word of the title.
    ChicagoStyle IgnoreFunc = optionsChicago
)

type TitleConverter Uses

type TitleConverter struct {
    // contains filtered or unexported fields
}

A TitleConverter converts a string to title case according to its style.

func NewTitleConverter Uses

func NewTitleConverter(style IgnoreFunc) *TitleConverter

NewTitleConverter returns a new TitleConverter set to enforce the specified style.

Code:

tc := NewTitleConverter(APStyle)
fmt.Println(tc.Title("the last of the mohicans"))

Output:

The Last of the Mohicans

func (*TitleConverter) Title Uses

func (tc *TitleConverter) Title(s string) string

Title returns a copy of the string s in title case format.

Package transform imports 5 packages (graph) and is imported by 13 packages. Updated 2017-11-18. Refresh now. Tools for package owners.