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)