Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Emails = FieldFunc("email", func(s []byte) (bool, []byte) { trimmedS := TrimPunctuation(s) if !bytes.Contains(s, []byte("@")) { return false, s } for _, tld := range tlds { if bytes.HasSuffix(s, tld) { return true, trimmedS } } return false, s })
Emails finds email addresses.
TrimPunctuation(s) return bytes.HasPrefix(trimmedS, []byte("#")), trimmedS })trimmedS :=
Hashtags finds #hashtags.
var Mentions = FieldFunc("mention", func(s []byte) (bool, []byte) { trimmedS := TrimPunctuation(s) return bytes.HasPrefix(trimmedS, []byte("@")), trimmedS })
Mentions finds @twitter style mentions.
var Punctuation = `.?!'",;`
Punctuation is a string of common punctuation and quotation characters.
var URLs = FieldFunc("url", func(s []byte) (bool, []byte) { trimmedS := TrimPunctuation(s) if bytes.Contains(s, []byte("@")) { return false, s } if bytes.HasPrefix(trimmedS, []byte("http")) || bytes.HasPrefix(trimmedS, []byte("www")) { return true, trimmedS } for _, tld := range tlds { if bytes.HasSuffix(trimmedS, tld) { return true, trimmedS } } return false, s })
URL finds web addresses.
Functions ¶
func TrimPunctuation ¶
TrimPunctuation trims off Punctuation characters.
Types ¶
type ErrNoMatch ¶
type ErrNoMatch []byte
ErrNoMatch is returned when a match was expected but can not be found. Can be returned from FieldFunc.
func (ErrNoMatch) Error ¶
func (e ErrNoMatch) Error() string
type Expander ¶
Expander holds a map of note kinds to expander functions that will be used to replace the text in the original string.
type FinderFunc ¶
FinderFunc represents a function capable of finding notes.
func FieldFunc ¶
func FieldFunc(kind string, fn func(b []byte) (bool, []byte)) FinderFunc
FieldFunc returns a FinderFunc that finds notes on a per field basis. The fn returns true if it's a match, and optionally a subset of the the match. The returned []byte must be contained in the source string, otherwise ErrNoMatch will be returned.
type Notes ¶
type Notes []*Note
Notes is a sortable slice of Note objects.
func FindMany ¶
FindMany runs all finders against the source and returns a slice of notes or an error.
func FindManyString ¶
FindManyString runs all finders against the source and returns a slice of notes or an error.
func FindString ¶
FindString uses the Finder to find notes within the specified string.