Skip to content

Latest commit

 

History

History
87 lines (65 loc) · 1.43 KB

README.md

File metadata and controls

87 lines (65 loc) · 1.43 KB

tokens

test Coverage Status https://goreportcard.com/report/github.com/wmentor/tokens https://pkg.go.dev/github.com/wmentor/tokens License: MIT

Text to tokens Go library.

Token get insensitive mode

package main

import (
	"fmt"
	"strings"

	"github.com/wmentor/tokens"
)

func main() {

	txt := "Hello, my little friend!"

	tokenizer := tokens.New(strings.NewReader(txt))

	for {
		tok, err := range tokenizer.Token()
		if err != nil { // io.EOF
			break
		}
		fmt.Println(tok)
	}
}

Result:

hello
,
my
little
friend
!

Case sensitive mode:

package main

import (
	"fmt"
	"strings"

	"github.com/wmentor/tokens"
)

func main() {

	txt := "Hello, my little friend!"

	tokenizer := tokens.New(strings.NewReader(txt), tokens.WithCaseSensitive())

	for {
		tok, err := range tokenizer.Token()
		if err != nil { // io.EOF
			break
		}
		fmt.Println(tok)
	}
}

Result:

Hello
,
my
liTTle
friend
!