splitter

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 0 Imported by: 0

README

Splitter

Splitter is a simple Go package that allows you to split strings according to specified rules.

Installation

Run the following Go command to install the splitter package:

$ go get -u github.com/leaqved/splitter

Add the following import to your code:

import "github.com/leaqved/splitter"

License

Distributed under the MIT License. See LICENSE.md for more information.

Documentation

Overview

Package splitter implements a string splitting package. It defines a type, Splitter, with Buffer to store and change data, and Rule functions that control its behavior.

Package splitter implements a string splitting package. It defines a type, Splitter, with Buffer to store and change data, and Rule functions that control its behavior.

Package splitter implements a string splitting package. It defines a type, Splitter, with Buffer to store and change data, and Rule functions that control its behavior.

Package splitter implements a string splitting package. It defines a type, Splitter, with Buffer to store and change data, and Rule functions that control its behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer represents a temporary storage for Splitter.

func (*Buffer) GetAll

func (b *Buffer) GetAll() ([]rune, []rune, []string)

GetAll returns incoming, current and done slices.

func (*Buffer) GetCurrent

func (b *Buffer) GetCurrent() []rune

GetCurrent returns current slice.

func (*Buffer) GetDone

func (b *Buffer) GetDone() []string

GetDone returns done slice.

func (*Buffer) GetIncoming

func (b *Buffer) GetIncoming() []rune

GetIncoming returns incoming slice.

func (*Buffer) GetLeft

func (b *Buffer) GetLeft() (rune, bool)

GetLeft returns the last element of the current slice.

Returns false if the current slice is empty.

func (*Buffer) GetRight

func (b *Buffer) GetRight() (rune, bool)

GetRight returns the first element of the incoming slice.

Returns false if the incoming slice is empty.

type CharRule added in v1.1.0

type CharRule func(char rune) bool

CharRule function should return true if given character satisfies the rule and false otherwise.

func AnyChar added in v1.2.0

func AnyChar() CharRule

AnyChar returns a CharRule that returns true in any case.

func CharInSet added in v1.2.0

func CharInSet[T comparable](set map[rune]T) CharRule

CharInSet returns a CharRule that checks if character is represented in the set.

func (CharRule) And added in v1.1.0

func (r CharRule) And(another CharRule) CharRule

And returns a logical conjunction of two CharRules.

func (CharRule) Or added in v1.2.0

func (r CharRule) Or(another CharRule) CharRule

And returns a logical disjunction of two CharRules.

type Option

type Option func(*Splitter)

Option function is applied in constructor function of the Splitter.

func AddJoin

func AddJoin(rules ...Rule) Option

AddJoin returns an Option that adds Rule functions to the join section of the Splitter.

func AddSkip

func AddSkip(rules ...Rule) Option

AddSkip returns an Option that adds Rule functions to the skip section of the Splitter.

func AddSplit

func AddSplit(rules ...Rule) Option

AddSplit returns an Option that adds Rule functions to the split section of the Splitter.

type Rule

type Rule func(*Buffer) bool

Rule function gains access to Buffer data using its public methods.

Should return true if current Buffer state satisfies the rule and false otherwise.

func After added in v1.1.0

func After(rule CharRule) Rule

After returns a Rule that checks if the last character in Buffer satisfies the CharRule.

func Before added in v1.1.0

func Before(rule CharRule) Rule

Before returns a Rule that checks if the next character incoming in Buffer satisfies the CharRule.

func Everything added in v1.2.0

func Everything() Rule

Everything returns a Rule that returns true in any case.

func WordInSet added in v1.2.0

func WordInSet[T comparable](set map[string]T) Rule

CharInSet returns a Rule that checks if current word in Buffer is represented in the set.

func (Rule) And added in v1.1.0

func (r Rule) And(another Rule) Rule

And returns a logical conjunction of two Rules.

func (Rule) Or added in v1.2.0

func (r Rule) Or(another Rule) Rule

And returns a logical disjunction of two Rules.

type Splitter

type Splitter struct {
	// contains filtered or unexported fields
}

A Splitter represents an active object that splits strings according to Rule functions.

func New

func New(opts ...Option) *Splitter

New creates a new Splitter and applies Option functions to it.

func (*Splitter) Split

func (s *Splitter) Split(str string) []string

Split splits the string according to Rule functions of the Splitter.

Returns the resulting slice.

Jump to

Keyboard shortcuts

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