forked from gSpera/morse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
62 lines (53 loc) · 1.92 KB
/
options.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package mltmorse
// IgnoreHandler ignores the error and returns nothing
func IgnoreHandler(error) string { return "" }
// PanicHandler is a handler that panics when an error occurs
func PanicHandler(err error) string { panic(err) }
// ConverterOption is a function that modifies a Converter
// The main use of ConvertOption is inside NewConverter
type ConverterOption func(Converter) Converter
// WithHandler sets the handler for the Converter
func WithHandler(handler ErrorHandler) ConverterOption {
return func(c Converter) Converter {
c.Handling = handler
return c
}
}
// WithLowercaseHandling sets if the Converter may convert to uppercase before checking inside the EncodingMap
func WithLowercaseHandling(lowercaseHandling bool) ConverterOption {
return func(c Converter) Converter {
c.convertToUpper = lowercaseHandling
return c
}
}
// WithTrailingSeparator sets if the Converter may trail the charSeparator
func WithTrailingSeparator(trailingSpace bool) ConverterOption {
return func(c Converter) Converter {
c.trailingSeparator = trailingSpace
return c
}
}
// WithCharSeparator sets the Character Separator
// The CharSeparator is the character used to separate two characters inside a Word
func WithCharSeparator(charSeparator string) ConverterOption {
return func(c Converter) Converter {
c.charSeparator = charSeparator
return c
}
}
// WithWordSeparator sets the Word Separator
// The Word Separator is used to separate two words, usually this is the Character Separator, a Space and another Character Separator
func WithWordSeparator(wordSeparator string) ConverterOption {
return func(c Converter) Converter {
c.wordSeparator = wordSeparator
return c
}
}
// WithStrNormalizer sets the string normalizer function
// The Word Separator is used to normalize string
func WithStrNormalizer(normalizer StrNormalizer) ConverterOption {
return func(c Converter) Converter {
c.Normalizer = normalizer
return c
}
}