updated GetMatch(uint) + add GetAllMatch()
This commit is contained in:
parent
427d7d06c8
commit
756bbca0b1
|
@ -73,17 +73,17 @@ func (s Scheme) GetMatch(n uint8) ([]string, error) {
|
|||
|
||||
/* (2) Iterate to find index (exclude strings) */
|
||||
ni := -1
|
||||
for i, l := 0, len(s) ; i < l ; i++ {
|
||||
for _, m := range s {
|
||||
|
||||
// ignore strings
|
||||
if len(s[i].pat) > 0 { continue }
|
||||
if len(m.pat) > 0 { continue }
|
||||
|
||||
// increment match counter : ni
|
||||
ni++
|
||||
|
||||
// if expected index -> return matches
|
||||
if uint8(ni) == n {
|
||||
return s[i].buf, nil
|
||||
return m.buf, nil
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -91,4 +91,25 @@ func (s Scheme) GetMatch(n uint8) ([]string, error) {
|
|||
/* (3) If nothing found -> return empty set */
|
||||
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
|
||||
|
||||
}
|
Loading…
Reference in New Issue