mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
chirp: remove regex dependency
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
2a67beaacf
commit
e64cecac8e
@ -10,7 +10,6 @@
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -89,7 +88,21 @@ func (b *BIRDClient) exec(cmd string, args ...interface{}) (string, error) {
|
|||||||
return b.readResponse()
|
return b.readResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
var respCodeRegex = regexp.MustCompile(`^\d{4}[ -]`)
|
// hasResponseCode reports whether the provided byte slice is
|
||||||
|
// prefixed with a BIRD response code.
|
||||||
|
// Equivalent regex: `^\d{4}[ -]`.
|
||||||
|
func hasResponseCode(s []byte) bool {
|
||||||
|
if len(s) < 5 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, b := range s[:4] {
|
||||||
|
if '0' <= b && b <= '9' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return s[4] == ' ' || s[4] == '-'
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BIRDClient) readResponse() (string, error) {
|
func (b *BIRDClient) readResponse() (string, error) {
|
||||||
var resp strings.Builder
|
var resp strings.Builder
|
||||||
@ -105,7 +118,7 @@ func (b *BIRDClient) readResponse() (string, error) {
|
|||||||
if _, err := resp.Write(out); err != nil {
|
if _, err := resp.Write(out); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if respCodeRegex.Match(out) {
|
if hasResponseCode(out) {
|
||||||
done = out[4] == ' '
|
done = out[4] == ' '
|
||||||
}
|
}
|
||||||
if !done {
|
if !done {
|
||||||
|
Loading…
Reference in New Issue
Block a user