textutil

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package textutil provides text manipulation and encoding utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureUTF8

func EnsureUTF8(s string) string

EnsureUTF8 ensures a string is valid UTF-8. If already valid UTF-8, returns as-is. Otherwise attempts charset detection and conversion. Falls back to replacing invalid bytes with replacement character.

func FirstLine

func FirstLine(s string) string

FirstLine returns the first line of a string. Useful for extracting clean error messages from multi-line outputs. Leading newlines are trimmed before extracting the first line.

func GetEncodingByName

func GetEncodingByName(name string) encoding.Encoding

GetEncodingByName returns an encoding for the given IANA charset name.

func SanitizeUTF8

func SanitizeUTF8(s string) string

SanitizeUTF8 replaces invalid UTF-8 bytes with replacement character.

func TruncateRunes

func TruncateRunes(s string, maxRunes int) string

TruncateRunes truncates a string to maxRunes runes (not bytes), adding "..." if truncated. This is UTF-8 safe and won't split multi-byte characters.

Types

This section is empty.

Jump to

Keyboard shortcuts

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