github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/values/number_list.go (about) 1 // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package values 4 5 import ( 6 "github.com/TeaOSLab/EdgeNode/internal/zero" 7 "github.com/iwind/TeaGo/types" 8 "strings" 9 ) 10 11 type NumberList struct { 12 ValueMap map[float64]zero.Zero 13 } 14 15 func NewNumberList() *NumberList { 16 return &NumberList{ 17 ValueMap: map[float64]zero.Zero{}, 18 } 19 } 20 21 func ParseNumberList(v string) *NumberList { 22 var list = NewNumberList() 23 if len(v) == 0 { 24 return list 25 } 26 27 var lines = strings.Split(v, "\n") 28 for _, line := range lines { 29 line = strings.TrimSpace(line) 30 if len(line) == 0 { 31 continue 32 } 33 34 var values = strings.Split(line, ",") 35 for _, value := range values { 36 value = strings.TrimSpace(value) 37 if len(value) > 0 { 38 list.ValueMap[types.Float64(value)] = zero.Zero{} 39 } 40 } 41 } 42 return list 43 } 44 45 func (this *NumberList) Contains(f float64) bool { 46 _, ok := this.ValueMap[f] 47 return ok 48 }