rename

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package rename provides functions for cleaning and formatting strings of known words and group names.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Amp

func Amp(s string) string

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

func Case(name string) string

Case returns the exact syntax of the known named group.

Example:

Case("beer") = "BEER"
Case("lkcc") = "LKCC"
Case("noclass") = "NoClass"

func Connect

func Connect(w string, position, last int) string

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

func Fix(w string, position, last int) string

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

func FixHyphen(w string) string

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

func Format(s string) string

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

func PreSuffix(s string, title cases.Caser) string

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 Sequence

func Sequence(w string, i int) string

Sequence formats the w string if it is the first word in the words slice.

func TrimDot

func TrimDot(s string) string

TrimDot removes a trailing dot from s.

Example:

TrimDot("hello.") = "hello"
TrimDot("hello..") = "hello."

func TrimThe

func TrimThe(name string) string

TrimThe drops "The" prefix whenever the named site ends with "BBS" or "FTP". This is to avoid the same site name being both "The X BBS" and "X BBS".

Example:

TrimThe("The X BBS") = "X BBS"
TrimThe("The X") = "The X"

func Word

func Word(s string) string

Word applies upper casing to known acronyms, initalisms and abbreviations. And lower casing to ordinal numbers 1st through to 13th. Otherwise it returns an empty string.

Example:

Word("1sT") = "1st"
Word("iso") = "ISO"

Types

This section is empty.

Jump to

Keyboard shortcuts

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