Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteIterator ¶
func Bytes ¶
func Bytes(s []byte, sep []byte) *ByteIterator
Bytes slices s into all subslices separated by sep.
If s does not contain sep and sep is not empty, Bytes returns a slice of length 1 whose only element is s.
If sep is empty, Bytes splits after each UTF-8 sequence. If both s and sep are empty, Bytes returns an empty slice.
Bytes returns an iterator over subslices. Use Iterator.Next to loop, and Iterator.Value to get the current subslice.
Example ¶
package main
import (
"fmt"
"github.com/clipperhouse/split"
)
func main() {
text := []byte("Hello, 世界. Nice dog! 👍🐶")
sep := []byte(" ")
split := split.Bytes(text, sep)
for split.Next() {
fmt.Println(split.Value())
}
}
func BytesAny ¶
func BytesAny(s []byte, separators []byte) *ByteIterator
BytesAny slices s into all subslices separated by any bytes in sep.
If s does not contain sep and sep is not empty, BytesAny returns a slice of length 1 whose only element is s.
If sep is empty, BytesAny splits after each UTF-8 sequence. If both s and sep are empty, BytesAny returns an empty slice.
BytesAny returns an iterator over subslices. Use Iterator.Next to loop, and Iterator.Value to get the current subslice.
type Iterator ¶
type Iterator[T seq] struct {
// contains filtered or unexported fields
}
Iterator is an iterator over subslices of `[]byte` or `string`. See Iterator.Next and Iterator.Value.
func (*Iterator[T]) Next ¶
Next tests whether there are any remaining subslices.
Intended for use in a for loop. Inside the loop, retrieve the current subslice with Iterator.Value.
func (*Iterator[T]) ToArray ¶
func (it *Iterator[T]) ToArray() []T
ToArray collects all the subslices into an array.
This is a convenience method, and the result should identical to strings|bytes.Split from the standard library. You should just use strings|bytes.Split if your goal is an array of results.
func (*Iterator[T]) Value ¶
func (it *Iterator[T]) Value() T
Value retrieves the value of the current subslice. Use it with Iterator.Next.
type StringIterator ¶
func String ¶
func String(s string, separator string) *StringIterator
String slices s into all substrings separated by sep.
If s does not contain sep and sep is not empty, String returns a slice of length 1 whose only element is s.
If sep is empty, String splits after each UTF-8 sequence. If both s and sep are empty, String returns an empty slice.
String returns an iterator over substrings. Use Iterator.Next to loop, and Iterator.Value to get the current substring.
Example ¶
package main
import (
"fmt"
"github.com/clipperhouse/split"
)
func main() {
text := "Hello, 世界. Nice dog! 👍🐶"
sep := " "
split := split.String(text, sep)
for split.Next() {
fmt.Println(split.Value())
}
}
func StringAny ¶
func StringAny(s string, chars string) *StringIterator
StringAny slices s into all substrings separated by any Unicode code point in chars.
If s does not contain any Unicode code point in chars, and chars is not empty, StringAny returns a slice of length 1 whose only element is s.
If chars is empty, StringAny splits after each UTF-8 sequence. If both s and chars are empty, StringAny returns an empty slice.
StringAny returns an iterator over substrings. Use Iterator.Next to loop, and Iterator.Value to get the current substrings.