Documentation
¶
Overview ¶
titlecase is a package for converting strings to title case format, which is a style traditionally used for the titles of books, movies, songs and plays. The style is also often used for headlines in newspapers, essays and blogs.
Rules ¶
Generally, all words are capitalised apart from:
- Articles (a, an, the)
- Conjunctions (and, or, but)
- Prepositions (in, on, for, up)
However the specifics of the rules depend on the chosen style as the title case format is not an agreed universal standard.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
Convert returns the provided string to title case, where all major words are capitalised and all minor words all lowercased. Zero or more functional options can be passed to configure how the string is converted.
Example (Book) ¶
package main
import (
"fmt"
"github.com/revett/titlecase"
)
func main() {
s, _ := titlecase.Convert("lord of the flies")
fmt.Println(s)
}
Output: Lord of the Flies
Example (Film) ¶
package main
import (
"fmt"
"github.com/revett/titlecase"
)
func main() {
s, _ := titlecase.Convert("once upon a time in hollywood")
fmt.Println(s)
}
Output: Once Upon a Time in Hollywood
Example (Play) ¶
package main
import (
"fmt"
"github.com/revett/titlecase"
)
func main() {
s, _ := titlecase.Convert("much ado about nothing")
fmt.Println(s)
}
Output: Much Ado About Nothing
func Debug ¶ added in v0.4.0
func Debug(c *converter)
Debug is a functional option for configuring debug logging to be enabled.
func WithParser ¶ added in v0.4.1
WithParser is a functional option that allows the default parsing function (which carries out tokenisation and part-of-speech tagging) to be set.