-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
57 lines (47 loc) · 1.13 KB
/
utils.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
// Copyright 2019 vogo. All rights reserved.
package aliwepaystat
import (
"fmt"
"regexp"
"strconv"
"strings"
)
func Contains(s string, f string) bool {
return strings.Contains(s, f)
}
func ContainsAny(s string, f ...string) bool {
for _, a := range f {
if strings.Contains(s, a) {
return true
}
}
return false
}
func EitherContainsAny(s1, s2 string, f ...string) bool {
for _, a := range f {
if strings.Contains(s1, a) || strings.Contains(s2, a) {
return true
}
}
return false
}
var (
regexCsvLineFieldsSuffixBlank, _ = regexp.Compile("[ ]+,")
)
func replaceCsvLineFieldsSuffixBlank(bytes []byte) []byte {
return regexCsvLineFieldsSuffixBlank.ReplaceAll(bytes, []byte{','})
}
func RoundFloat(f float64) float64 {
v, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", f), 64)
return v
}
var (
investmentRegex1, _ = regexp.Compile(".*财富.*买入.*")
investmentRegex2, _ = regexp.Compile(".*基金.*买入.*")
investmentRegex3, _ = regexp.Compile(".*股票.*买入.*")
)
func IsInvestment(s string) bool {
return investmentRegex1.MatchString(s) ||
investmentRegex2.MatchString(s) ||
investmentRegex3.MatchString(s)
}