Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CharacterClass ¶
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 ¶
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 ¶
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 ¶
FieldFunc splits a line into fields based on a separator. This abstraction enables custom field splitting logic and testing.
func Fixed ¶
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]
type Line ¶ added in v0.1.0
type Line string
Line is a single line of input text to be split into fields.