MCPcopy Create free account
hub / github.com/chainreactors/spray / ParseStatus

Function ParseStatus

pkg/utils.go:463–508  ·  view source on GitHub ↗

ParseStatus parses the input string and updates the preset status filters.

(preset []int, changed string)

Source from the content-addressed store, hash-verified

461
462// ParseStatus parses the input string and updates the preset status filters.
463func ParseStatus(preset []int, changed string) []int {
464 if changed == "" {
465 return preset
466 }
467
468 parseToken := func(s string) (int, bool) {
469 s = strings.TrimSpace(s)
470 if strings.HasSuffix(s, "*") {
471 prefix := s[:len(s)-1]
472 if t, err := strconv.Atoi(prefix); err == nil {
473 return t, true // isPrefix = true
474 }
475 } else if t, err := strconv.Atoi(s); err == nil {
476 return t, false // isPrefix = false
477 }
478 return 0, false
479 }
480
481 if strings.HasPrefix(changed, "+") {
482 for _, s := range strings.Split(changed[1:], ",") {
483 if t, _ := parseToken(s); t != 0 {
484 preset = append(preset, t)
485 }
486 }
487 } else if strings.HasPrefix(changed, "!") {
488 for _, s := range strings.Split(changed[1:], ",") {
489 if t, _ := parseToken(s); t != 0 {
490 newPreset := preset[:0]
491 for _, val := range preset {
492 if val != t {
493 newPreset = append(newPreset, val)
494 }
495 }
496 preset = newPreset
497 }
498 }
499 } else {
500 preset = []int{}
501 for _, s := range strings.Split(changed, ",") {
502 if t, _ := parseToken(s); t != 0 {
503 preset = append(preset, t)
504 }
505 }
506 }
507 return UniqueInts(preset)
508}
509
510func UniqueInts(input []int) []int {
511 seen := make(map[int]bool)

Callers 1

PrepareMethod · 0.92

Calls 1

UniqueIntsFunction · 0.85

Tested by

no test coverage detected