Helper routines to abbreviate long strings.

Russtopia dd4eae5d19 Update 'README.md' 3 years ago
README.md dd4eae5d19 Update 'README.md' 3 years ago
brevity.go 16fcaf95e0 Added source files 3 years ago
brevity_test.go 16fcaf95e0 Added source files 3 years ago

README.md

package brevity // import "blitter.com/go/brevity"

brevity is a package with some functions to summarize long strings, by prepending or appending ellipses based on splitting by separators and/or total constrained length.

func PostEllipse(s, sep string, depth int) string
PostEllipse returns s, potentially shortened and appended with ellipses (...) if (depth) or more occurrences of sep are present.

▾ Example

Code:

inStr := "A:B:C:D"
outStr := PostEllipse(inStr, ":", 3)
fmt.Println(outStr)
Output:

A:B:C ...

func PreEllipse(s, sep string, depth int) string
PreEllipse returns s, potentially shortened and prepended with ellipses (...) if (depth) or more occurrences of sep are present.

▾ Example

Code:

inStr := "A:B:C:D"
outStr := PreEllipse(inStr, ":", 3)
fmt.Println(outStr)
Output:

... B:C:D