notations

package module
v0.0.0-...-bd9a066 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2015 License: MIT Imports: 2 Imported by: 0

README

notations

Extracts from a string, @mentions, #tags and/or any other [utf8 symbol][keyword]. The approach uses a tokenizer instead of the common regex, beacuse of this, it has better performance and works well for large amout of text.

Installation

go get github.com/jmsegrev/notations

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Notation

type Notation struct {
	Key   rune
	Value string
	Slice Slice
}

type Notations

type Notations map[string][]Notation

func Extract

func Extract(text string, chars string) Notations

Returns the Notations extracted from the text, uses the distics chars as notation indetifier.

Example
txt := `@username assume this is a reply, by @anotherusername that has
	some #tag1 and #tag2. It also works the same way for %any &other *symbol,
	but you provably will only use things like $2377.12.`

notationsMap := notations.Extract(txt, "@#$%&*$")
for key, notations := range notationsMap {
	fmt.Printf("%s: ", key)
	for _, notation := range notations {
		fmt.Printf("%s ", notation.Value)
	}
	fmt.Println("")
}
Output:

@: username anotherusername
#: tag1 tag2
%: any
&: other
*: symbol
$: 2377.12

type Slice

type Slice struct {
	Begin int
	End   int
}

Jump to

Keyboard shortcuts

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