misspell

package
v2.0.7+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2018 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const Legal = `` /* 2042-byte string literal not displayed */

Legal provides licensing info.

Variables

View Source
var DictAmerican = []string{}/* 3238 elements not displayed */

DictAmerican converts UK spellings to US spellings

View Source
var DictBritish = []string{}/* 2954 elements not displayed */

DictBritish converts US spellings to UK spellings

View Source
var DictMain = []string{}/* 56094 elements not displayed */

DictMain is the main rule set, not including locale-specific spellings

Functions

func ByteEqualFold

func ByteEqualFold(a, b byte) bool

ByteEqualFold does ascii compare, case insensitive

func ByteToLower

func ByteToLower(eax byte) byte

ByteToLower converts an ascii byte to lower case uses a branchless algorithm

func ByteToUpper

func ByteToUpper(x byte) byte

ByteToUpper converts an ascii byte to upper cases Uses a branchless algorithm

func CaseVariations

func CaseVariations(word string, style WordCase) []string

CaseVariations returns If AllUpper or First-Letter-Only is upcased: add the all upper case version If AllLower, add the original, the title and upcase forms If Mixed, return the original, and the all upcase form

func ReadTextFile

func ReadTextFile(filename string) (string, error)

ReadTextFile returns the contents of a file, first testing if it is a text file

returns ("", nil) if not a text file
returns ("", error) if error
returns (string, nil) if text

unfortunately, in worse case, this does

 1 stat
 1 open,read,close of 512 bytes
 1 more stat,open, read everything, close (via ioutil.ReadAll)
This could be kinder to the filesystem.

This uses some heuristics of the file's extension (e.g. .zip, .txt) and uses a sniffer to determine if the file is text or not. Using file extensions isn't great, but probably good enough for real-world use. Golang's built in sniffer is problematic for differnet reasons. It's optimized for HTML, and is very limited in detection. It would be good to explicitly add some tests for ELF/DWARF formats to make sure we never corrupt binary files.

func RemoveEmail

func RemoveEmail(s string) string

RemoveEmail remove email-like strings, e.g. "nickg+junk@xfoobar.com", "nickg@xyz.abc123.biz"

func RemoveHost

func RemoveHost(s string) string

RemoveHost removes host-like strings "foobar.com" "abc123.fo1231.biz"

func RemoveNotWords

func RemoveNotWords(s string) string

RemoveNotWords blanks out all the not words

func RemovePath

func RemovePath(s string) string

RemovePath attempts to strip away embedded file system paths, e.g.

/foo/bar or /static/myimg.png

TODO: windows style

func StringEqualFold

func StringEqualFold(s1, s2 string) bool

StringEqualFold ASCII case-insensitive comparison golang toUpper/toLower for both bytes and strings appears to be Unicode based which is super slow based from https://codereview.appspot.com/5180044/patch/14007/21002

func StringHasPrefixFold

func StringHasPrefixFold(s1, s2 string) bool

StringHasPrefixFold is similar to strings.HasPrefix but comparison is done ignoring ASCII case. /

func StripURL

func StripURL(s string) string

StripURL attemps to replace URLs with blank spaces, e.g.

"xxx http://foo.com/ yyy -> "xxx          yyyy"

Types

type Diff

type Diff struct {
	Filename  string
	FullLine  string
	Line      int
	Column    int
	Original  string
	Corrected string
}

Diff is datastructure showing what changed in a single line

type Replacer

type Replacer struct {
	Replacements []string
	Debug        bool
	// contains filtered or unexported fields
}

Replacer is the main struct for spelling correction

func New

func New() *Replacer

New creates a new default Replacer using the main rule list

func (*Replacer) AddRuleList

func (r *Replacer) AddRuleList(additions []string)

AddRuleList appends new rules. Input is in the same form as Strings.Replacer: [ old1, new1, old2, new2, ....] Note: does not check for duplictes

func (*Replacer) Compile

func (r *Replacer) Compile()

Compile compiles the rules. Required before using the Replace functions

func (*Replacer) RemoveRule

func (r *Replacer) RemoveRule(ignore []string)

RemoveRule deletes existings rules. TODO: make inplace to save memory

func (*Replacer) Replace

func (r *Replacer) Replace(input string) (string, []Diff)

Replace is corrects misspellings in input, returning corrected version

along with a list of diffs.

func (*Replacer) ReplaceGo

func (r *Replacer) ReplaceGo(input string) (string, []Diff)

ReplaceGo is a specialized routine for correcting Golang source files. Currently only checks comments, not identifiers for spelling.

func (*Replacer) ReplaceReader

func (r *Replacer) ReplaceReader(raw io.Reader, w io.Writer, next func(Diff)) error

ReplaceReader applies spelling corrections to a reader stream. Diffs are emitted through a callback.

type StringReplacer

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

StringReplacer replaces a list of strings with replacements. It is safe for concurrent use by multiple goroutines.

func NewStringReplacer

func NewStringReplacer(oldnew ...string) *StringReplacer

NewStringReplacer returns a new Replacer from a list of old, new string pairs. Replacements are performed in order, without overlapping matches.

func (*StringReplacer) Replace

func (r *StringReplacer) Replace(s string) string

Replace returns a copy of s with all replacements performed.

func (*StringReplacer) WriteString

func (r *StringReplacer) WriteString(w io.Writer, s string) (n int, err error)

WriteString writes s to w with all replacements performed.

type WordCase

type WordCase int

WordCase is an enum of various word casing styles

const (
	CaseUnknown WordCase = iota
	CaseLower
	CaseUpper
	CaseTitle
)

Various WordCase types.. likely to be not correct

func CaseStyle

func CaseStyle(word string) WordCase

CaseStyle returns what case style a word is in

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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