strutil

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package strutil provides string utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeUTF16

func DecodeUTF16(u []uint16) string

DecodeUTF16 decodes UTF-16 code units to a string.

func EncodeUTF16

func EncodeUTF16(s string) []uint16

EncodeUTF16 encodes a string to UTF-16. Returns the UTF-16 code units.

func SplitUTF16

func SplitUTF16(s string, maxCodeUnits int) []string

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

func TruncateUTF16(s string, maxCodeUnits int) string

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

func TruncateUTF16WithEllipsis(s string, maxCodeUnits int) string

TruncateUTF16WithEllipsis truncates a string and adds an ellipsis if truncated. The ellipsis counts as 1 UTF-16 code unit.

func UTF16Len

func UTF16Len(s string) int

UTF16Len returns the number of UTF-16 code units in a string. This is useful for checking message lengths against platform limits.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL