Skip to content

Remove duplicate truncate functions, reuse utils.Truncate#29

Merged
yinwm merged 1 commit intosipeed:mainfrom
DevEverything01:fix/deduplicate-truncate
Feb 12, 2026
Merged

Remove duplicate truncate functions, reuse utils.Truncate#29
yinwm merged 1 commit intosipeed:mainfrom
DevEverything01:fix/deduplicate-truncate

Conversation

@DevEverything01
Copy link
Contributor

Summary

  • Remove 3 duplicate private truncate implementations across the codebase, replacing them with the existing utils.Truncate
  • The removed functions (truncateString, truncateStringDingTalk, truncateText) were byte-based and could corrupt multi-byte UTF-8 characters; utils.Truncate is rune-safe

Details

Package Removed function Issue
channels/telegram.go truncateString byte-based, no "..." suffix
channels/dingtalk.go truncateStringDingTalk byte-based, no "..." suffix
voice/transcriber.go truncateText byte-based, has "..." but not rune-safe

All call sites now use utils.Truncate which already exists and handles Unicode correctly.

Test plan

  • go build ./... passes
  • go vet ./... passes
  • go test ./... passes (all existing tests green)

Multiple packages had their own private truncate implementations:
- channels/telegram.go: truncateString (byte-based, no "...")
- channels/dingtalk.go: truncateStringDingTalk (byte-based, no "...")
- voice/transcriber.go: truncateText (byte-based, with "...")

All three are functionally equivalent to the existing utils.Truncate,
which already handles rune-safe truncation and appends "..." correctly.

Replace all private copies with utils.Truncate and delete the dead code.
@yinwm
Copy link
Collaborator

yinwm commented Feb 12, 2026

Thanks for the PR!

@yinwm yinwm merged commit 91e8abf into sipeed:main Feb 12, 2026
@DevEverything01 DevEverything01 deleted the fix/deduplicate-truncate branch February 17, 2026 04:14
emadomedher pushed a commit to emadomedher/picoclaw that referenced this pull request Feb 17, 2026
…ncate

Remove duplicate truncate functions, reuse utils.Truncate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants