Documentation
¶
Overview ¶
Package strutil provides string utility functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeUTF16 ¶
DecodeUTF16 decodes UTF-16 code units to a string.
func EncodeUTF16 ¶
EncodeUTF16 encodes a string to UTF-16. Returns the UTF-16 code units.
func SplitUTF16 ¶
SplitUTF16 splits a string into chunks of at most maxCodeUnits UTF-16 code units. Useful for splitting long messages for APIs with character limits.
func TruncateUTF16 ¶
TruncateUTF16 truncates a string to the specified number of UTF-16 code units. This is important for APIs like Telegram, Discord, and Slack that count characters in UTF-16 code units rather than bytes or runes.
The function ensures the string is truncated at a valid UTF-16 boundary, avoiding splitting surrogate pairs (emojis, CJK characters, etc.).
func TruncateUTF16WithEllipsis ¶
TruncateUTF16WithEllipsis truncates a string and adds an ellipsis if truncated. The ellipsis counts as 1 UTF-16 code unit.
Types ¶
This section is empty.