-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtranslit.go
34 lines (28 loc) · 873 Bytes
/
translit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Package translit provides transliteration transformer.
// See subpackages for language-specific transformers.
package translit
import (
"golang.org/x/text/transform"
"github.com/mxmCherry/translit/internal/transformer"
"github.com/mxmCherry/translit/internal/tree"
"github.com/mxmCherry/translit/internal/tree/maptree"
)
// Factory represents pre-compiled tree builder/factory.
type Factory interface {
// Transformer returns/builds a "fresh" transliteration transformer.
Transformer() transform.Transformer
}
type factory struct {
rules tree.Node
}
// Map pre-compiles string-to-string transliteration rule map into transformer factory.
func Map(rules map[string]string) Factory {
r := new(maptree.Node)
tree.Populate(r, rules)
return &factory{
rules: r,
}
}
func (f *factory) Transformer() transform.Transformer {
return transformer.New(f.rules)
}