util

package
v0.0.0-...-26182ce Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2015 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package util provides some helpful functions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiToken

type MultiToken []rune

MultiToken represents a run of runes that can be used to tokenize a stream of runes.

func NewMultiToken

func NewMultiToken(s string) MultiToken

func (MultiToken) ScanToken

func (m MultiToken) ScanToken(rd *bufio.Reader) (rns []rune, err error)

ScanToken returns the run of runes terminated by m, not including the terminator.

Example
const input = "hi\r\nhow\r\nare\r\nyou"
var tok = MultiToken([]rune{'\r', '\n'})

r := bufio.NewReader(strings.NewReader(input))

for {
	rs, err := tok.ScanToken(r)

	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("Got input: %s\n", string(rs))
}
Output:

Got input: hi
Got input: how
Got input: are
EOF

Jump to

Keyboard shortcuts

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