From 78ee22b04474c843f2c6d529bf6bfcfaa8739d01 Mon Sep 17 00:00:00 2001 From: M09Ic Date: Thu, 12 Jan 2023 17:12:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96status=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86,=20=E8=BF=90=E8=A1=8C=E9=80=9A=E8=BF=87`+`=E6=88=96`!?= =?UTF-8?q?`=E5=9C=A8=E5=8E=9F=E6=9C=89=E7=9A=84=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E4=B8=8A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/option.go | 32 +++----------------------------- internal/utils.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/internal/option.go b/internal/option.go index ae625e2..0c32482 100644 --- a/internal/option.go +++ b/internal/option.go @@ -200,35 +200,9 @@ func (opt *Option) PrepareRunner() (*Runner, error) { logs.Log.Important("Advance Mod: " + s.String()) } - if opt.BlackStatus != "" { - for _, s := range strings.Split(opt.BlackStatus, ",") { - si, err := strconv.Atoi(s) - if err != nil { - return nil, err - } - BlackStatus = append(BlackStatus, si) - } - } - - if opt.WhiteStatus != "" { - for _, s := range strings.Split(opt.WhiteStatus, ",") { - si, err := strconv.Atoi(s) - if err != nil { - return nil, err - } - WhiteStatus = append(WhiteStatus, si) - } - } - - if opt.FuzzyStatus != "" { - for _, s := range strings.Split(opt.FuzzyStatus, ",") { - si, err := strconv.Atoi(s) - if err != nil { - return nil, err - } - FuzzyStatus = append(FuzzyStatus, si) - } - } + BlackStatus = parseStatus(BlackStatus, opt.BlackStatus) + WhiteStatus = parseStatus(WhiteStatus, opt.WhiteStatus) + FuzzyStatus = parseStatus(FuzzyStatus, opt.FuzzyStatus) // prepare word dicts := make([][]string, len(opt.Dictionaries)) diff --git a/internal/utils.go b/internal/utils.go index 97d2b5c..c92ce14 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "net/url" "path" + "strconv" "strings" ) @@ -18,6 +19,42 @@ func parseExtension(s string) string { return "" } +func parseStatus(preset []int, changed string) []int { + if changed == "" { + return preset + } + if strings.HasPrefix(changed, "+") { + for _, s := range strings.Split(changed[1:], ",") { + if t, err := strconv.Atoi(s); err != nil { + continue + } else { + preset = append(preset, t) + } + } + } else if strings.HasPrefix(changed, "!") { + for _, s := range strings.Split(changed[1:], ",") { + for i, status := range preset { + if t, err := strconv.Atoi(s); err != nil { + break + } else if t == status { + preset = append(preset[:i], preset[i+1:]...) + break + } + } + } + } else { + preset = []int{} + for _, s := range strings.Split(changed, ",") { + if t, err := strconv.Atoi(s); err != nil { + continue + } else { + preset = append(preset, t) + } + } + } + return preset +} + func loadFileToSlice(filename string) ([]string, error) { var ss []string content, err := ioutil.ReadFile(filename)