Documentation
¶
Overview ¶
Package fix provides functions for cleaning and formatting strings of known words and group names.
Index ¶
- func Abbreviation(s string) string
- func Amp(s string) string
- func Cell(s string) string
- func Connect(w string, position, last int) string
- func Fix(w string, position, last int) string
- func Format(s string) string
- func Hyphen(w string) string
- func PreSuffix(s string, title cases.Caser) string
- func Sequence(w string, i int) string
- func StripChars(s string) string
- func StripStart(s string) string
- func TrimDot(s string) string
- func TrimSP(s string) string
- func TrimThe(name string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abbreviation ¶
Abbreviation applies upper casing to known acronyms, initialisms and abbreviations. And lower casing to ordinal numbers 1st through to 13th. Otherwise it returns an empty string.
Example:
Abbreviation("1ST") = "1st" Abbreviation("iso") = "ISO"
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/fix" ) func main() { fmt.Println(fix.Abbreviation("whq")) }
Output: WHQ
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 Cell ¶ added in v1.0.3
Cell returns a copy of s with custom formatting for storage in a database cell. All words will be upper cased and stipped of incompatible characters.
Example:
Cell(" Defacto2 demo group. ") = "DEFACTO2 DEMO GROUP" Cell("the x bbs") = "X BBS"
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/releaser/fix" "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 := fix.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/releaser/fix" "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 := fix.Fix(w, i, len(s)) if x != "" { s[i] = x } } fmt.Println(strings.Join(s, " ")) }
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"
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/fix" ) func main() { fmt.Println(fix.Format("the BEST bbs")) }
Output: The Best BBS
func Hyphen ¶
Hyphen applies fix.Fix to hyphenated words.
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/fix" ) func main() { s := "members-of-2000ad-will-meet-at-3pm" fmt.Println(fix.Hyphen(s)) }
Output: Members-of-2000AD-Will-Meet-at-3PM
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 StripChars ¶
StripChars removes all the incompatible characters that cannot be used for releaser URL paths.
Example:
StripChars("Café!") = "Café" StripChars(".~[[@]hello[@]]~.") = "hello"
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/fix" ) func main() { fmt.Println(fix.StripChars("!!!OMG-WTF???")) }
Output: OMG-WTF
func StripStart ¶
StripStart removes the non-alphanumeric characters from the start of the string.
Example:
StripStart(" - [*] checkbox") = "checkbox"
func TrimDot ¶
TrimDot removes a trailing dot from s.
Example:
TrimDot("hello.") = "hello" TrimDot("hello..") = "hello."
func TrimSP ¶
TrimSP removes duplicate spaces from the string.
Example:
TrimSP("hello world") = "hello world"
Example ¶
package main import ( "fmt" "github.com/Defacto2/releaser/fix" ) func main() { fmt.Print(fix.TrimSP(" hello world ")) }
Output: hello world
Types ¶
This section is empty.