mirror of
https://github.com/oxynote/oxynote.git
synced 2026-10-19 03:45:58 +02:00
* 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>
29 lines
635 B
Go
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)
|
|
}
|