Documentation
¶
Overview ¶
Package stringutil provides common string utility functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollapseRepeatedErrorWrappers ¶ added in v0.61.0
CollapseRepeatedErrorWrappers removes consecutive duplicate wrapper segments from a wrapped Go error chain rendered as "outer: middle: inner".
Third-party transports sometimes wrap an error with the same message twice (mcp-go's streamable_http wraps a send failure as "failed to send request" at two nesting levels), so a user-facing error reads
transport error: failed to send request: failed to send request: Post "…"
": " is not only a Go wrapping boundary — it also occurs inside quoted URLs, JSON, captured stderr and validation text. Deleting an adjacent repeat there would silently destroy real content. So a segment is dropped ONLY when all of the following hold:
- it is byte-identical to the segment immediately before it, and
- it is not the last segment (the root cause is never merged away), and
- it looks like a wrapper phrase rather than a payload — see isWrapperPhrase.
A chain with no adjacent wrapper repeats is returned unchanged.
func ContainsIgnoreCase ¶
ContainsIgnoreCase checks if s contains substr, ignoring case.
func UTF8Prefix ¶ added in v0.72.0
UTF8Prefix returns the longest prefix of s that is at most n bytes long and does not end in the middle of a multi-byte UTF-8 sequence. Slicing a string at a raw byte offset (s[:n]) can leave a partial rune at the end, which is invalid UTF-8 and is rewritten to U+FFFD by JSON encoding.
Only a rune that actually straddles the cut is dropped: malformed input (a stray continuation byte) is cut at n rather than discarding the complete runes before it.
Types ¶
This section is empty.