-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoundex.go
More file actions
42 lines (32 loc) · 718 Bytes
/
Copy pathsoundex.go
File metadata and controls
42 lines (32 loc) · 718 Bytes
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
35
36
37
38
39
40
41
42
package soundex
import (
"errors"
)
var (
ErrUnsupportedAlgorithm error = errors.New("unsupported algorithm")
ErrInvalidCharacter error = errors.New("invalid character")
ErrEmptyString error = errors.New("empty string")
)
const (
AlgoOrigin uint64 = 1 << iota
AlgoImproved
)
type Soundex interface {
Code(string) (string, error)
}
func New(algorithm ...uint64) (Soundex, error) {
alg := AlgoOrigin
if len(algorithm) > 1 {
return nil, ErrUnsupportedAlgorithm
} else if len(algorithm) == 1 {
alg = algorithm[0]
}
switch alg {
case AlgoOrigin:
return &soundexOrigin{}, nil
case AlgoImproved:
return &soundexImproved{}, nil
default:
return nil, ErrUnsupportedAlgorithm
}
}