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 ¶
- func CheckSorted(lines []string, opts SortOptions) string
- func Sort(lines []string)
- func SortLines(lines []string, opts ...SortOption)
- func SortLinesWithOpts(lines []string, opts SortOptions)
- func TrimLines(lines []string) []string
- func Uniq(lines []string) []string
- func UniqueConsecutive(lines []string, ignoreCase bool) []string
- type SortOption
- type SortOptions
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 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 UniqueConsecutive ¶
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.
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.