aboutsummaryrefslogtreecommitdiff
path: root/src/net/parse.go
diff options
context:
space:
mode:
authorDan Peterson <dpiddy@gmail.com>2016-08-16 13:33:27 -0300
committerMatthew Dempsky <mdempsky@google.com>2016-08-17 03:12:29 +0000
commit00b779aeed9e0345e4bdbb38c85df63a6352b954 (patch)
treef7b1cdfda140fdfb52e08bdad2c1ce073704b546 /src/net/parse.go
parent9c13eb3729988af8be1fd00175bacdd20c7d4206 (diff)
downloadgo-00b779aeed9e0345e4bdbb38c85df63a6352b954.tar.xz
net: simplify internal dtoi and xtoi funcs
Callers pass strings sliced as necessary instead of giving an offset. Fixes #16350 Change-Id: I7ba896f6ff09e0fd0094ca6c5af5d9a81622f15e Reviewed-on: https://go-review.googlesource.com/27206 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/parse.go')
-rw-r--r--src/net/parse.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/net/parse.go b/src/net/parse.go
index ed82a7769b..363c83f6ce 100644
--- a/src/net/parse.go
+++ b/src/net/parse.go
@@ -123,16 +123,16 @@ func getFields(s string) []string { return splitAtBytes(s, " \r\t\n") }
// Bigger than we need, not too big to worry about overflow
const big = 0xFFFFFF
-// Decimal to integer starting at &s[i0].
-// Returns number, new offset, success.
-func dtoi(s string, i0 int) (n int, i int, ok bool) {
+// Decimal to integer.
+// Returns number, characters consumed, success.
+func dtoi(s string) (n int, i int, ok bool) {
n = 0
neg := false
if len(s) > 0 && s[0] == '-' {
neg = true
s = s[1:]
}
- for i = i0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
+ for i = 0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
n = n*10 + int(s[i]-'0')
if n >= big {
if neg {
@@ -141,7 +141,7 @@ func dtoi(s string, i0 int) (n int, i int, ok bool) {
return big, i, false
}
}
- if i == i0 {
+ if i == 0 {
return 0, i, false
}
if neg {
@@ -151,11 +151,11 @@ func dtoi(s string, i0 int) (n int, i int, ok bool) {
return n, i, true
}
-// Hexadecimal to integer starting at &s[i0].
-// Returns number, new offset, success.
-func xtoi(s string, i0 int) (n int, i int, ok bool) {
+// Hexadecimal to integer.
+// Returns number, characters consumed, success.
+func xtoi(s string) (n int, i int, ok bool) {
n = 0
- for i = i0; i < len(s); i++ {
+ for i = 0; i < len(s); i++ {
if '0' <= s[i] && s[i] <= '9' {
n *= 16
n += int(s[i] - '0')
@@ -172,7 +172,7 @@ func xtoi(s string, i0 int) (n int, i int, ok bool) {
return 0, i, false
}
}
- if i == i0 {
+ if i == 0 {
return 0, i, false
}
return n, i, true
@@ -186,7 +186,7 @@ func xtoi2(s string, e byte) (byte, bool) {
if len(s) > 2 && s[2] != e {
return 0, false
}
- n, ei, ok := xtoi(s[:2], 0)
+ n, ei, ok := xtoi(s[:2])
return byte(n), ok && ei == 2
}