transform

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2017 License: MIT Imports: 5 Imported by: 52

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IgnoreFunc

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

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

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

func NewTitleConverter

func NewTitleConverter(style IgnoreFunc) *TitleConverter

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

Example
package main

import (
	"fmt"
	"path/filepath"
)

var testdata = filepath.Join("..", "testdata")

func main() {
	tc := NewTitleConverter(APStyle)
	fmt.Println(tc.Title("the last of the mohicans"))
}
Output:

The Last of the Mohicans

func (*TitleConverter) Title

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL