frontend: add generic whois shorten mode

This commit is contained in:
Lan Tian
2021-06-20 02:20:18 +08:00
parent 6a8b3a0e55
commit 41329da7cb
2 changed files with 33 additions and 1 deletions

View File

@@ -49,3 +49,33 @@ func dn42WhoisFilter(whois string) string {
return commandResult
}
}
/* experimental, behavior may change */
func shortenWhoisFilter(whois string) string {
commandResult := ""
skippedLines := 0
for _, s := range strings.Split(whois, "\n") {
s = strings.TrimSpace(s)
shouldSkip := false
shouldSkip = shouldSkip || len(s) == 0
shouldSkip = shouldSkip || len(s) > 80
shouldSkip = shouldSkip || len(s) > 0 && s[0] == '#'
shouldSkip = shouldSkip || !strings.Contains(s, ":")
shouldSkip = shouldSkip || strings.Index(s, ":") > 20
if shouldSkip {
skippedLines++
continue
}
commandResult += s + "\n"
}
if skippedLines > 0 {
return commandResult + fmt.Sprintf("\n%d line(s) skipped.\n", skippedLines)
} else {
return commandResult
}
}