mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
d692cc0cc6
* Add Find Skills and Install Skills * Improvements * fix file name * Update pkg/skills/clawhub_registry.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix * Comments addressed * Resolve comments * fix tests * fixes * Comments resolved * Update pkg/skills/search_cache_repro_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * minor fix * fix test * fixes --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
26 lines
653 B
Go
26 lines
653 B
Go
package utils
|
|
|
|
// Truncate returns a truncated version of s with at most maxLen runes.
|
|
// Handles multi-byte Unicode characters properly.
|
|
// If the string is truncated, "..." is appended to indicate truncation.
|
|
func Truncate(s string, maxLen int) string {
|
|
runes := []rune(s)
|
|
if len(runes) <= maxLen {
|
|
return s
|
|
}
|
|
// Reserve 3 chars for "..."
|
|
if maxLen <= 3 {
|
|
return string(runes[:maxLen])
|
|
}
|
|
return string(runes[:maxLen-3]) + "..."
|
|
}
|
|
|
|
// DerefStr dereferences a pointer to a string and
|
|
// returns the value or a fallback if the pointer is nil.
|
|
func DerefStr(s *string, fallback string) string {
|
|
if s == nil {
|
|
return fallback
|
|
}
|
|
return *s
|
|
}
|