updated GetMatch(uint) + add GetAllMatch()

This commit is contained in:
xdrm-brackets 2018-04-26 23:39:10 +02:00
parent 427d7d06c8
commit 756bbca0b1
1 changed files with 24 additions and 3 deletions

View File

@ -73,17 +73,17 @@ func (s Scheme) GetMatch(n uint8) ([]string, error) {
/* (2) Iterate to find index (exclude strings) */ /* (2) Iterate to find index (exclude strings) */
ni := -1 ni := -1
for i, l := 0, len(s) ; i < l ; i++ { for _, m := range s {
// ignore strings // ignore strings
if len(s[i].pat) > 0 { continue } if len(m.pat) > 0 { continue }
// increment match counter : ni // increment match counter : ni
ni++ ni++
// if expected index -> return matches // if expected index -> return matches
if uint8(ni) == n { if uint8(ni) == n {
return s[i].buf, nil return m.buf, nil
} }
} }
@ -92,3 +92,24 @@ func (s Scheme) GetMatch(n uint8) ([]string, error) {
return nil, fmt.Errorf("Index out of range (max: %d)", ni) return nil, fmt.Errorf("Index out of range (max: %d)", ni)
} }
// GetAllMatch returns all the indexed match (excluding string matchers)
func (s Scheme) GetAllMatch() [][]string {
match := make([][]string, 0, len(s))
for _, m := range s {
// ignore strings
if len(m.pat) > 0 { continue }
match = append(match, m.buf)
}
return match
}