fix

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package fix 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 Abbreviation

func Abbreviation(s string) string

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"

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 Cell added in v1.0.3

func Cell(s string) string

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

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/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

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/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

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 Hyphen

func Hyphen(w string) string

Hyphen applies fix.Fix to hyphenated words.

Example
package main

import (
	"fmt"

	"github.com/Defacto2/releaser/fix"
)

func main() {
	const txt = "members-of-2000ad-will-meet-at-3pm"
	fmt.Println(fix.Hyphen(txt))
}
Output:

Members-of-2000AD-Will-Meet-at-3PM

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 StripChars

func StripChars(s string) string

StripChars removes all the incompatible characters that cannot be used for releaser URL paths.

Example:

StripChars("Café!") = "Café"
StripChars(".~[[@]hello[@]]~.") = "hello"

func StripStart

func StripStart(s string) string

StripStart removes the non-alphanumeric characters from the start of the string.

Example:

StripStart(" - [*] checkbox") = "checkbox"

func TrimDot

func TrimDot(s string) string

TrimDot removes a trailing dot from s.

Example:

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

func TrimSP

func TrimSP(s string) string

TrimSP removes duplicate spaces from the string.

Example:

TrimSP("hello              world") = "hello world"

func TrimThe

func TrimThe(name string) string

TrimThe drops "The " prefix whenever the named string ends with " BBS" or " FTP". It is to avoid unique site names duplication, e.g. "The X BBS" and "X BBS".

Example:

TrimThe("The X BBS") = "X BBS"
TrimThe("X BBS") = "X BBS"
TrimThe("The X") = "The X" // no change

Types

This section is empty.

Jump to

Keyboard shortcuts

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