textutil

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClipBytes

func ClipBytes(b []byte, r *IntRange) ([]byte, int, int, error)

ClipBytes returns a byte slice clipped to r and the start/end offsets. When r is nil, the original slice and full offsets are returned.

func ClipBytesByRange

func ClipBytesByRange(b []byte, br BytesRange) ([]byte, int, int, error)

ClipBytesByRange clips using BytesRange (offset+length) without exposing IntRange. When both fields are zero, the original slice is returned.

func ClipHead

func ClipHead(text string, totalSize, maxBytes, maxLines int) (string, int, int)

ClipHead returns the first portion of text. If maxLines > 0, it clips by lines only. Otherwise, if maxBytes > 0, it clips by bytes.

func ClipLines

func ClipLines(b []byte, r *IntRange) ([]byte, int, int, error)

ClipLines returns a byte slice corresponding to line range r and the start/end byte offsets mapped from lines. Lines are 0-based; To is exclusive. When r is nil, the original slice and full offsets are returned.

func ClipLinesByRange

func ClipLinesByRange(b []byte, lr LineRange) ([]byte, int, int, error)

ClipLinesByRange clips using LineRange (StartLine+LineCount) without exposing IntRange. When both fields are zero, the original slice is returned.

func ClipTail

func ClipTail(text string, totalSize, maxBytes, maxLines int) (string, int, int)

ClipTail returns the last portion of text. If maxLines > 0, it clips by lines only. Otherwise, if maxBytes > 0, it clips by bytes.

func ExtractSignatures

func ExtractSignatures(text string, maxBytes int) string

ExtractSignatures collects signature-like lines and optionally bounds the response by maxBytes.

func RuneTruncate

func RuneTruncate(s string, n int) string

RuneTruncate safely truncates a UTF-8 string to at most n runes without splitting a multi-byte character. When n <= 0 it returns an empty string.

Types

type BytesRange

type BytesRange struct {
	// byte range is ignored. When both byte and line ranges are unset, the
	// full (optionally MaxBytes-truncated) content is returned.
	OffsetBytes int64 `json:"offsetBytes,omitempty"` // 0-based byte offset; default 0
	LengthBytes int   `json:"lengthBytes,omitempty"` // bytes to read; 0 => use MaxBytes cap

}

type GrepFile

type GrepFile struct {
	// Path is the logical path under the effective root (e.g. workspace-
	// relative or root-relative). URI may carry the canonical address
	// when needed by higher layers (e.g. workspace://... or file://...).
	Path string
	URI  string

	// SearchHash is a stable hash of the grep query parameters used to
	// produce this result set (e.g. pattern, root, path, filters). It allows
	// UIs to de-duplicate or uniquely identify rows across searches.
	SearchHash string

	// RangeKey is an optional, human-readable range identifier derived from
	// the first snippet window (e.g. "12-24"). It is intended as a secondary
	// disambiguator when needed by UIs.
	RangeKey string

	Matches  int     // number of matches in this file
	Score    float32 // optional heuristic score (e.g. density of matches)
	Snippets []Snippet
	Omitted  int // number of snippets or matches omitted due to limits
}

GrepFile groups snippets belonging to a single source file.

type GrepStats

type GrepStats struct {
	Scanned   int  // total files scanned
	Matched   int  // files with at least one match
	Truncated bool // true when limits prevented a full scan
}

GrepStats summarizes a grep-style search across one or more files. It is generic enough to be reused by resources- and message-level tools that perform lexical search.

type IntRange

type IntRange struct {
	From *int `json:"from,omitempty"`
	To   *int `json:"to,omitempty"`
}

IntRange represents a half-open interval [From, To) with 0-based indices. A nil range, or missing endpoints, is considered invalid by helpers.

type LineRange

type LineRange struct {

	// StartLine and LineCount describe a 1-based line slice. When StartLine > 0
	// this mode is used in preference to the byte range.
	StartLine int `json:"startLine,omitempty"` // 1-based start line
	LineCount int `json:"lineCount,omitempty"` // number of lines; 0 => until EOF or MaxBytes

}

type Snippet

type Snippet struct {
	// StartLine and EndLine are 1-based line numbers within the source
	// document. When unknown, they may be left as 0.
	StartLine int
	EndLine   int

	// OffsetBytes is the byte offset of the first byte of Text within
	// the original document. LengthBytes is the size of Text in bytes.
	OffsetBytes int64
	LengthBytes int

	// Text contains the snippet content. Implementations may apply
	// additional truncation to enforce byte/line limits.
	Text string

	// Hits optionally records match positions as (lineOffset, columnOffset)
	// pairs relative to StartLine within this snippet.
	Hits [][2]int

	// Cut indicates that the snippet was truncated due to configured
	// limits (e.g. max bytes or max lines).
	Cut bool
}

Snippet models a text fragment selected from a larger document. It is intended to be reusable by tools that present match previews (e.g. grep-style search over files or conversation messages).

Jump to

Keyboard shortcuts

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