update
This commit is contained in:
13
internal/pkg/textutil/textutil.go
Normal file
13
internal/pkg/textutil/textutil.go
Normal file
@ -0,0 +1,13 @@
|
||||
// Package textutil 提供文本处理辅助函数。
|
||||
package textutil
|
||||
|
||||
// Summarize 按 rune 截断字符串,避免中文被按字节切断;超出部分追加省略号。
|
||||
//
|
||||
// 行为与原项目 handlers.summarize 完全一致(含省略号字符 U+2026)。
|
||||
func Summarize(s string, n int) string {
|
||||
runes := []rune(s)
|
||||
if len(runes) <= n {
|
||||
return s
|
||||
}
|
||||
return string(runes[:n]) + "…"
|
||||
}
|
||||
Reference in New Issue
Block a user