소스 검색

x/net/icmp: make use of strconv

There is no circular dependencies, no need to hesitate to use it.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/185900043
Mikio Hara 11 년 전
부모
커밋
2e20f33919
1개의 변경된 파일5개의 추가작업 그리고 17개의 파일을 삭제
  1. 5 17
      icmp/helper_unix.go

+ 5 - 17
icmp/helper_unix.go

@@ -8,6 +8,7 @@ package icmp
 
 import (
 	"net"
+	"strconv"
 	"syscall"
 )
 
@@ -56,7 +57,10 @@ func zoneToUint32(zone string) uint32 {
 	if ifi, err := net.InterfaceByName(zone); err == nil {
 		return uint32(ifi.Index)
 	}
-	n, _, _ := dtoi(zone, 0)
+	n, err := strconv.Atoi(zone)
+	if err != nil {
+		return 0
+	}
 	return uint32(n)
 }
 
@@ -69,19 +73,3 @@ func last(s string, b byte) int {
 	}
 	return i
 }
-
-const big = 0xFFFFFF
-
-func dtoi(s string, i0 int) (n int, i int, ok bool) {
-	n = 0
-	for i = i0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
-		n = n*10 + int(s[i]-'0')
-		if n >= big {
-			return 0, i, false
-		}
-	}
-	if i == i0 {
-		return 0, i, false
-	}
-	return n, i, true
-}