mirror of
https://github.com/tinygo-org/net.git
synced 2026-08-15 00:43:39 +00:00
move xtoi2 to parse.go
This commit is contained in:
@@ -85,15 +85,3 @@ func ParseMAC(s string) (hw HardwareAddr, err error) {
|
|||||||
err:
|
err:
|
||||||
return nil, &AddrError{Err: "invalid MAC address", Addr: s}
|
return nil, &AddrError{Err: "invalid MAC address", Addr: s}
|
||||||
}
|
}
|
||||||
|
|
||||||
// xtoi2 converts the next two hex digits of s into a byte.
|
|
||||||
// If s is longer than 2 bytes then the third byte must be e.
|
|
||||||
// If the first two bytes of s are not hex digits or the third byte
|
|
||||||
// does not match e, false is returned.
|
|
||||||
func xtoi2(s string, e byte) (byte, bool) {
|
|
||||||
if len(s) > 2 && s[2] != e {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
n, ei, ok := xtoi(s[:2])
|
|
||||||
return byte(n), ok && ei == 2
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -52,6 +52,18 @@ func xtoi(s string) (n int, i int, ok bool) {
|
|||||||
return n, i, true
|
return n, i, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// xtoi2 converts the next two hex digits of s into a byte.
|
||||||
|
// If s is longer than 2 bytes then the third byte must be e.
|
||||||
|
// If the first two bytes of s are not hex digits or the third byte
|
||||||
|
// does not match e, false is returned.
|
||||||
|
func xtoi2(s string, e byte) (byte, bool) {
|
||||||
|
if len(s) > 2 && s[2] != e {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
n, ei, ok := xtoi(s[:2])
|
||||||
|
return byte(n), ok && ei == 2
|
||||||
|
}
|
||||||
|
|
||||||
// Convert unsigned integer to decimal string.
|
// Convert unsigned integer to decimal string.
|
||||||
func uitoa(val uint) string {
|
func uitoa(val uint) string {
|
||||||
if val == 0 { // avoid string allocation
|
if val == 0 { // avoid string allocation
|
||||||
|
|||||||
Reference in New Issue
Block a user