misspell: github.com/client9/misspell Index | Files | Directories

package misspell

import "github.com/client9/misspell"

Package misspell corrects commonly misspelled English words in source files.


Package Files

ascii.go case.go legal.go mime.go notwords.go replace.go stringreplacer.go url.go words.go


const Legal = "" /* 2044 byte string literal not displayed */

Legal provides licensing info.


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


DictAmerican converts UK spellings to US spellings

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


DictBritish converts US spellings to UK spellings

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


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

func ByteEqualFold Uses

func ByteEqualFold(a, b byte) bool

ByteEqualFold does ascii compare, case insensitive

func ByteToLower Uses

func ByteToLower(eax byte) byte

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

func ByteToUpper Uses

func ByteToUpper(x byte) byte

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

func CaseVariations Uses

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 Uses

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 Uses

func RemoveEmail(s string) string

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

func RemoveHost Uses

func RemoveHost(s string) string

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

func RemoveNotWords Uses

func RemoveNotWords(s string) string

RemoveNotWords blanks out all the not words

func RemovePath Uses

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 Uses

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 Uses

func StringHasPrefixFold(s1, s2 string) bool

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

func StripURL Uses

func StripURL(s string) string

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

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

type Diff Uses

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 Uses

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

Replacer is the main struct for spelling correction

func New Uses

func New() *Replacer

New creates a new default Replacer using the main rule list

func (*Replacer) AddRuleList Uses

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 Uses

func (r *Replacer) Compile()

Compile compiles the rules. Required before using the Replace functions

func (*Replacer) RemoveRule Uses

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

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

func (*Replacer) Replace Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

Replace returns a copy of s with all replacements performed.

func (*StringReplacer) WriteString Uses

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

WriteString writes s to w with all replacements performed.

type WordCase Uses

type WordCase int

WordCase is an enum of various word casing styles

const (
    CaseUnknown WordCase = iota

Various WordCase types.. likely to be not correct

func CaseStyle Uses

func CaseStyle(word string) WordCase

CaseStyle returns what case style a word is in


cmd/misspellThe misspell command corrects commonly misspelled English words in source files.

Package misspell imports 11 packages (graph) and is imported by 4 packages. Updated 2019-03-12. Refresh now. Tools for package owners.