Helper routines to abbreviate long strings.
|
3 years ago | |
---|---|---|
README.md | 3 years ago | |
brevity.go | 3 years ago | |
brevity_test.go | 3 years ago |
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