Documentation
¶
Overview ¶
Package word provides functions for cleaning and formatting strings of known words and group names.
Index ¶
- func Abbreviation(lcase string) string
- func AbbreviationMix(s string) string
- func Amp(s string) string
- func Cell(s string) string
- func Connect(s string, position, last int) string
- func English(s string) string
- func Fix(s string, position, last int) string
- func Format(s string) string
- func Hyphen(s string) string
- func PreSuffix(s string) string
- func Sequence(s 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(s 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. It applies lower casing to ordinal numbers 1st through to 13th. Otherwise it returns an empty string.
It requires lowercase input, otherwise use the slower AbbreviationMix.
Example:
Abbreviation("1ST") = "1st"
Abbreviation("1sT") = ""
Abbreviation("iso") = "ISO"
Abbreviation("Iso") = ""
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/word"
)
func main() {
fmt.Println(word.Abbreviation("whq"))
}
Output: WHQ
func AbbreviationMix ¶
AbbreviationMix applies upper casing to known acronyms, initialisms and abbreviations. It applies lower casing to ordinal numbers 1st through to 13th. Otherwise it returns an empty string.
It supports mixed case input, however if s is confirmed to be lowercase, use the 2x faster Abbreviation.
Example:
Abbreviation("1ST") = "1st"
Abbreviation("1sT") = "1st"
Abbreviation("iso") = "ISO"
Abbreviation("Iso") = "ISO"
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 ¶
Cell returns a copy of s with custom formatting for storage in a database cell. All words will be upper cased and stripped of incompatible characters.
Example:
Cell(" Defacto2 demo group. ") = "DEFACTO2 DEMO GROUP"
Cell("the x bbs") = "X BBS"
func Connect ¶
Connect formats common connecting words based on the position in a slice. The goal is to allow for US style titles: The Best BBS and the Rest.
For optimal performance, it does not support mixed case strings.
Example:
Connect("at", 1, 99) = "at"
Connect("AT", 1, 99) = "at"
Connect("at", 0, 99) = ""
Connect("at", 99, 99) = ""
Connect("common", 8, 99) = ""
Example ¶
package main
import (
"fmt"
"strings"
"github.com/Defacto2/server/handler/releaser/word"
"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 := word.Connect(w, i, len(s))
if x != "" {
s[i] = x
}
}
fmt.Println(strings.Join(s, " "))
}
Output: Apple and Oranges
func Fix ¶
Fix formats the s 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/server/handler/releaser/word"
"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 := word.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. Some 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/server/handler/releaser/word"
)
func main() {
fmt.Println(word.Format("the BEST bbs"))
}
Output: The Best BBS
func Hyphen ¶
Hyphen replaces spaces in a sentence with hyphens. Each word is also parsed using [fix.Fix].
Example:
Hyphen("members of 2000ad will meet at 3pm") = "Members-of-2000AD-Will-Meet-at-3PM"
Example ¶
package main
import (
"fmt"
"github.com/Defacto2/server/handler/releaser/word"
)
func main() {
s := "members-of-2000ad-will-meet-at-3pm"
fmt.Println(word.Hyphen(s))
}
Output: Members-of-2000AD-Will-Meet-at-3PM
func PreSuffix ¶
PreSuffix formats the string if a known prefix or suffix is found. The title caser needs to be a language-specific title casing.
Example:
PreSuffix("12am") = "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/server/handler/releaser/word"
)
func main() {
fmt.Println(word.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/server/handler/releaser/word"
)
func main() {
fmt.Print(word.TrimSP(" hello world "))
}
Output: hello world
Types ¶
This section is empty.