Documentation
¶
Overview ¶
Package rename provides functions for cleaning and formatting strings of known words and group names.
Index ¶
- func Amp(s string) string
- func Case(name string) string
- func Connect(w string, position, last int) string
- func Fix(w string, position, last int) string
- func FixHyphen(w string) string
- func Format(s string) string
- func PreSuffix(s string, title cases.Caser) string
- func Sequence(w string, i int) string
- func TrimDot(s string) string
- func TrimThe(name string) string
- func Word(s string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Amp ¶
Amp formats the special ampersand (&) character in the string to be usable with a URL path in use by the group.
Example:
Amp("hello&&world") = "hello & world"
func Case ¶
Case returns the exact syntax of the known named group.
Example:
Case("beer") = "BEER"
Case("lkcc") = "LKCC"
Case("noclass") = "NoClass"
func Connect ¶
Connect formats common connecting word as the w string based on its position in a words slice.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/Defacto2/sceners/rename"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
func main() {
titleize := cases.Title(language.English, cases.NoLower)
const txt = "apple and oranges"
s := strings.Split(titleize.String(txt), " ")
for i, w := range s {
x := rename.Connect(w, i, len(s))
if x != "" {
s[i] = x
}
}
fmt.Println(strings.Join(s, " "))
}
Output: Apple and Oranges
func Fix ¶
Fix formats the w string based on its position in the words slice. The position is the index of the word in the words slice. The last is the index of the last word in the words slice.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/Defacto2/sceners/rename"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
func main() {
titleize := cases.Title(language.English, cases.NoLower)
const txt = "members of 2000ad will meet at 3pm"
s := strings.Split(titleize.String(txt), " ")
for i, w := range s {
x := rename.Fix(w, i, len(s))
if x != "" {
s[i] = x
}
}
fmt.Println(strings.Join(s, " "))
}
Output: Members of 2000AD Will Meet at 3PM
func FixHyphen ¶
FixHyphen applies rename.Fix to hyphenated words.
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/sceners/rename"
)
func main() {
const txt = "members-of-2000ad-will-meet-at-3pm"
fmt.Println(rename.FixHyphen(txt))
}
Output: Members-of-2000AD-Will-Meet-at-3PM
func Format ¶
Format returns a copy of s with custom formatting. Certain words and known acronyms will be upper cased, lower cased or title cased. Known named groups will be returned in their special casing. Trailing dots will be removed.
Example:
Format("hello world.") = "Hello World"
Format("the 12am group.") = "The 12AM Group"
func PreSuffix ¶
PreSuffix formats the w string if a known prefix or suffix is found. The title caser needs to be a language-specific title casing.
Example:
PreSuffix("12am", cases.Title(language.English, cases.NoLower)) = "12AM"
func TrimDot ¶
TrimDot removes a trailing dot from s.
Example:
TrimDot("hello.") = "hello"
TrimDot("hello..") = "hello."
Types ¶
This section is empty.