1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-24 06:09:01 +08:00
nali/internal/entity/entity.go

52 lines
761 B
Go
Raw Normal View History

2021-07-30 21:46:06 +08:00
package entity
import (
"strings"
)
type EntityType uint
const (
TypePlain = iota
TypeIPv4
TypeIPv6
TypeDomain
)
type Entity struct {
2021-07-30 22:30:27 +08:00
Loc []int // s[Loc[0]:Loc[1]]
2021-07-30 21:46:06 +08:00
Type EntityType
Text string
Info string
}
func (e Entity) ParseInfo() error {
return nil
}
type Entities []*Entity
func (es Entities) Len() int {
return len(es)
}
func (es Entities) Less(i, j int) bool {
2021-07-30 22:30:27 +08:00
return es[i].Loc[0] < es[j].Loc[0]
2021-07-30 21:46:06 +08:00
}
func (es Entities) Swap(i, j int) {
2021-07-30 22:30:27 +08:00
es[i], es[j] = es[j], es[i]
2021-07-30 21:46:06 +08:00
}
func (es Entities) String() string {
var result strings.Builder
for _, entity := range es {
result.WriteString(entity.Text)
2021-07-30 22:30:27 +08:00
if entity.Type != TypePlain && len(entity.Info) > 0 {
2021-07-30 21:46:06 +08:00
result.WriteString("[" + entity.Info + "] ")
}
}
return result.String()
2021-07-30 22:30:27 +08:00
}