textutil

package
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package textutil provides shared, UTF-8-safe text bounding helpers used by plugins, the downstream MCP client, and result/prompt shaping. Slicing a string at a raw byte offset can split a multi-byte rune and hand invalid UTF-8 to json.Marshal (which rewrites it to U+FFFD); every truncation in Prism should go through CutBytes instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CutBytes

func CutBytes(s string, limit int) (string, bool)

CutBytes returns s truncated to at most limit bytes without splitting a UTF-8 rune, plus whether truncation occurred. limit <= 0 disables truncation.

func Truncate

func Truncate(s string, limit int, suffix string) string

Truncate bounds s to limit bytes, appending suffix when content was removed. The suffix does not count against the limit so callers keep their existing size contracts for the payload portion. For a hard byte budget where the total output must not exceed limit, use TruncateWithin.

func TruncateWithin

func TruncateWithin(s string, limit int, suffix string) string

TruncateWithin bounds the total output — payload plus suffix — to limit bytes. Use it to enforce hard budgets (e.g. ToolSpec.MaxBytes) where even the truncation marker must not overflow the limit. When limit is too small to fit the suffix, the payload is hard-cut without a marker.

Types

This section is empty.

Jump to

Keyboard shortcuts

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