splitter

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CharacterClass

func CharacterClass(line Line, separator Separator) []string

CharacterClass splits on any character from the separator string. Similar to splitting on a regex character class [chars].

Example
package main

import (
	"fmt"

	"github.com/gloo-foo/testable/splitter"
)

func main() {
	fmt.Println(splitter.CharacterClass("a,b;c:d", ",;:"))
}
Output:
[a b c d]

func Exact

func Exact(line Line, separator Separator) []string

Exact always splits on the exact separator string. Unlike Whitespace, it treats " " as a literal space, not as "any whitespace".

Example
package main

import (
	"fmt"

	"github.com/gloo-foo/testable/splitter"
)

func main() {
	fmt.Println(splitter.Exact("a,b,,c", ","))
}
Output:
[a b  c]

func Whitespace

func Whitespace(line Line, separator Separator) []string

Whitespace splits on whitespace (spaces, tabs, etc.) when separator is " ". For any other separator, it splits on that exact string. This mimics awk's default field splitting behavior.

Example
package main

import (
	"fmt"

	"github.com/gloo-foo/testable/splitter"
)

func main() {
	fmt.Println(splitter.Whitespace("a  b   c", " "))
}
Output:
[a b c]

Types

type FieldFunc

type FieldFunc func(line Line, separator Separator) []string

FieldFunc splits a line into fields based on a separator. This abstraction enables custom field splitting logic and testing.

func Fixed

func Fixed(positions ...Position) FieldFunc

Fixed creates a FieldFunc that splits at fixed-width positions. Positions define where each field starts (0-based). The last position extends to the end of the line.

Example
package main

import (
	"fmt"

	"github.com/gloo-foo/testable/splitter"
)

func main() {
	split := splitter.Fixed(0, 3, 6)
	fmt.Println(split("abcdefghij", ""))
}
Output:
[abc def ghij]

func Pattern

func Pattern(splitFunc func(string) []string) FieldFunc

Pattern creates a FieldFunc that uses a custom splitting function. This allows for regex-based or other complex splitting logic.

type Line added in v0.1.0

type Line string

Line is a single line of input text to be split into fields.

type Position added in v0.1.0

type Position int

Position is a 0-based starting column of a fixed-width field.

type Separator added in v0.1.0

type Separator string

Separator selects how a Line is split into fields.

Jump to

Keyboard shortcuts

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