textutil

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package textutil provides text processing functions including sorting, deduplication, and trimming of string slices. Sort supports functional options for reverse, numeric, case-insensitive, and stable ordering.

Package textutil provides text processing utilities including sorting, deduplication, and trimming.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSorted

func CheckSorted(lines []string, opts SortOptions) string

CheckSorted verifies that lines are sorted according to options. Returns an error string if not sorted, or empty string if sorted.

func Sort

func Sort(lines []string)

Sort sorts a slice of strings in place alphabetically.

func SortLines

func SortLines(lines []string, opts ...SortOption)

SortLines sorts a slice of strings in place with options.

func SortLinesWithOpts

func SortLinesWithOpts(lines []string, opts SortOptions)

SortLinesWithOpts sorts a slice of strings in place using the options struct.

func TrimLines

func TrimLines(lines []string) []string

TrimLines trims whitespace from all lines.

func Uniq

func Uniq(lines []string) []string

Uniq returns unique lines from a slice (removes all duplicates, not just consecutive).

func UniqueConsecutive

func UniqueConsecutive(lines []string, ignoreCase bool) []string

UniqueConsecutive removes consecutive duplicate lines (like Unix uniq).

Types

type SortOption

type SortOption func(*SortOptions)

SortOption is a functional option for SortLines.

func WithIgnoreCase

func WithIgnoreCase() SortOption

WithIgnoreCase enables case-insensitive sorting.

func WithIgnoreLeading

func WithIgnoreLeading() SortOption

WithIgnoreLeading ignores leading blanks.

func WithNumeric

func WithNumeric() SortOption

WithNumeric enables numerical comparison.

func WithReverse

func WithReverse() SortOption

WithReverse reverses the sort order.

func WithStable

func WithStable() SortOption

WithStable enables stable sorting.

func WithUnique

func WithUnique() SortOption

WithUnique outputs only unique lines.

type SortOptions

type SortOptions struct {
	Reverse       bool // Reverse the result of comparisons
	Numeric       bool // Compare according to string numerical value
	Unique        bool // Output only unique lines
	IgnoreCase    bool // Fold lower case to upper case characters
	IgnoreLeading bool // Ignore leading blanks
	Stable        bool // Stabilize sort by disabling last-resort comparison
}

SortOptions configures sorting behavior.

Directories

Path Synopsis
Package diff provides line-based diff computation using the LCS algorithm, unified format output, and JSON structure comparison.
Package diff provides line-based diff computation using the LCS algorithm, unified format output, and JSON structure comparison.

Jump to

Keyboard shortcuts

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