oxynote/server/core/pkg/strutil/strutil.go
swithek 78c4244619
overhaul the notif inbox (#200)
* overhaul the notif inbox

* make hook summary abstract

---------

Co-authored-by: David <SE.David@protonmail.com>
Co-authored-by: david <58231312+davseby@users.noreply.github.com>
2026-10-06 19:03:49 +03:00

29 lines
635 B
Go

package strutil
import "strings"
// Ellipsize returns at most maxLen runes of s, appending a single
// ellipsis rune when the input was longer. A non-positive maxLen
// returns s unchanged.
func Ellipsize(s string, maxLen int) string {
if maxLen <= 0 {
return s
}
runes := []rune(s)
if len(runes) <= maxLen {
return s
}
return string(runes[:maxLen]) + "…"
}
// Preview returns at most maxLen runes of s, collapsed to a single line
// and trimmed, elided the way Ellipsize does.
func Preview(s string, maxLen int) string {
s = strings.ReplaceAll(s, "\n", " ")
s = strings.TrimSpace(s)
return Ellipsize(s, maxLen)
}