-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstring.go
More file actions
52 lines (43 loc) · 1.21 KB
/
string.go
File metadata and controls
52 lines (43 loc) · 1.21 KB
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
package numtow
import (
"github.com/gammban/numtow/lang"
"github.com/gammban/numtow/lang/en"
"github.com/gammban/numtow/lang/kz"
"github.com/gammban/numtow/lang/ru"
)
// String converts decimal number to words.
//
// String("1", lang.EN)
func String(decimal string, language lang.Lang, options ...interface{}) (words string, err error) {
switch language {
case lang.KZ:
o := kz.ParseOpts(options...)
return kz.String(decimal, o...)
case lang.RU:
o := ru.ParseOpts(options...)
return ru.String(decimal, o...)
case lang.EN:
o := en.ParseOpts(options...)
return en.String(decimal, o...)
case lang.Unknown:
return words, lang.ErrBadLanguage
default:
return words, lang.ErrBadLanguage
}
}
// MustString converts decimal number to words or panics on error.
func MustString(decimal string, language lang.Lang, options ...interface{}) string {
res, err := String(decimal, language, options...)
if err != nil {
panic(err)
}
return res
}
// StringOrZero converts decimal number to words or returns an empty string on error.
func StringOrZero(decimal string, language lang.Lang, options ...interface{}) string {
res, err := String(decimal, language, options...)
if err != nil {
return ""
}
return res
}