Documentation
¶
Overview ¶
Package abbrev is a pure-Go (no cgo) reimplementation of Ruby's `abbrev` standard library — MRI's [Abbrev.abbrev] and the [Array#abbrev] core extension.
Given a set of words it returns the set of unambiguous abbreviations: every prefix of a word that is a prefix of exactly one word in the set, mapped to that word, plus each full word mapped to itself. Prefixes shared by two or more words are ambiguous and omitted.
abbrev.Abbrev([]string{"ruby", "rules"})
// => {"rub":"ruby", "ruby":"ruby", "rule":"rules", "rules":"rules"}
The optional prefix argument restricts the result to words that start with the given string (only those words, and only abbreviations at least as long as the prefix, appear in the output) — mirroring MRI's String-pattern case.
The algorithm is a faithful port of upstream abbrev.rb (Akinori MUSHA), so it reproduces MRI 4.0.5 byte-for-byte, including its handling of empty words, duplicate words, and the prefix filter. It is the abbrev backend for go-embedded-ruby but is a standalone, runtime-free module.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abbrev ¶
Abbrev returns the set of unambiguous abbreviations for words as a map from each abbreviation (and each full word) to the full word it identifies.
It is a direct port of MRI's Abbrev.abbrev. An optional prefix may be passed; when present, only words starting with prefix are considered and only abbreviations that themselves start with prefix appear. Matching MRI, when a prefix is given the full word always maps to itself even if the prefix equals the whole word; passing more than one prefix uses only the first (extra arguments are ignored, as Ruby takes a single pattern).
The returned map is never nil; an empty word set (or one fully filtered out) yields an empty map.
Types ¶
This section is empty.
