textutil

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 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 cuts text to a budget measured in runes.

A byte budget applied to non-ASCII text is wrong twice over: it keeps far less than it promises, and it can end mid-rune, which JSON encoding then rewrites as U+FFFD. Every limit here counts runes and every cut lands on a rune boundary, so the output is always valid UTF-8.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TruncateMiddle

func TruncateMiddle(s string, limit int) (out string, removed int)

TruncateMiddle keeps the head and tail of s within limit runes and drops the middle, returning the kept text and how many runes it removed so a caller can say how much is missing.

func TruncateMiddleParts

func TruncateMiddleParts(s string, limit int) (head, tail string, removed int)

TruncateMiddleParts keeps a head and a tail of s within limit runes, drops everything between them, and reports how many runes it dropped. The budget goes two thirds to the head and one third to the tail. Callers that mark the seam need the two pieces; TruncateMiddle is the same cut already joined.

func TruncateRunes

func TruncateRunes(s string, limit int) string

TruncateRunes returns the first limit runes of s. A limit of zero or less keeps nothing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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