go-capitalize is a Go library for capitalizing proper names.
import "github.com/fonini/go-capitalize/capitalize"
The capitalize package exports a single Capitalize()
function. A simple example:
name, _ := capitalize.Capitalize("jonnas fonini")
fmt.Println(name) // will output: "Jonnas Fonini"
name, _ = capitalize.Capitalize("ruA DA praça xv")
fmt.Println(name) // will output: "Rua da Praça XV"
// With additional exceptions
options := capitalize.Options{
Exceptions: []string{"of"},
Surnames: []string{"McElroy"},
}
name, _ = capitalize.Capitalize("gørvel fadersdotter of giske", options)
fmt.Println(name) // will output: "Gørvel Fadersdotter of Giske"
name, _ = capitalize.Capitalize("john mcelroy", options)
fmt.Println(name) // will output: "John McElroy"
Thanks to Fausto Gonçalves Cintra for the original PHP code.