Documentation ¶
Overview ¶
Package confusables provides functions for identifying words that appear to be similar but use different characters.
Index ¶
- Variables
- func AddMapping(r rune, confusable string)
- func AddMappingWithDesc(r rune, confusable, runeDesc, confusableDesc string)
- func IsConfusable(s1, s2 string) bool
- func LoadMappings(r io.Reader) error
- func ToASCII(s string) string
- func ToNumber(s string) string
- func ToSkeleton(s string) string
- type ConfusableEntry
- type Confusables
- type Description
- type Diff
Constants ¶
This section is empty.
Variables ¶
var ErrIgnoreLine = errors.New("line should be ignored")
ErrIgnoreLine is raised when processing a line which should be ignored.
Functions ¶
func AddMapping ¶
AddMapping allows custom mappings to be defined for a rune.
func AddMappingWithDesc ¶
AddMappingWithDesc allows a custom mapping to be defined between a rune and its confusable and for a description to be provided for that mapping.
func IsConfusable ¶
IsConfusable checks if two strings are confusable of one another.
func LoadMappings ¶
LoadMappings reads r and loads in confusable mappings. Where a confusable already exists, this will override the mapping.
func ToSkeleton ¶
ToSkeleton converts a string to its skeleton form as defined by the skeleton algorithm in https://www.unicode.org/reports/tr39/#def-skeleton.
Types ¶
type ConfusableEntry ¶
type ConfusableEntry struct { Description Description Target string Source rune }
ConfusableEntry defines a parsed entry from a confusable mapping file.
func ParseLine ¶
func ParseLine(line string) (*ConfusableEntry, error)
ParseLine takes a confusable line and returns a ConfusableEntry. If a line should be skipped an ErrIgnoreLine error is raised.
type Confusables ¶
type Confusables struct {
// contains filtered or unexported fields
}
Confusables provides functions for identifying words that appear to be similar but use different characters.
func (*Confusables) ToASCII ¶
func (c *Confusables) ToASCII(s string) string
ToASCII converts characters in a string to their ASCII equivalent if possible.
func (*Confusables) ToASCIIDiff ¶
func (c *Confusables) ToASCIIDiff(s string) (string, []Diff)
func (*Confusables) ToNumber ¶
func (c *Confusables) ToNumber(s string) string
ToNumber converts characters in a string that look like numbers into numbers.
type Description ¶
Description describes a mapping for a confusable.
type Diff ¶
type Diff struct { Confusable *string Description *Description Rune rune }
Diff details the mapping from a rune to its confusable if it exists.
func ToASCIIDiff ¶
ToASCIIDiff converts characters in a string to their ASCII equivalent if possible.
func ToSkeletonDiff ¶
ToSkeletonDiff returns a slice of Diff detailing the changes that have been made within the string to reach its skeleton form.