parse.gno
0.55 Kb · 27 lines
1package game
2
3// indexFrom returns the index of the first c in s at or after i, or len(s)
4// when there is none.
5func indexFrom(s string, i int, c byte) int {
6 for i < len(s) && s[i] != c {
7 i++
8 }
9 return i
10}
11
12// digits parses a non-empty string of decimal digits. Kill counts are never
13// negative, so there is no sign to read.
14func digits(s string) (int64, bool) {
15 if len(s) == 0 {
16 return 0, false
17 }
18 n := int64(0)
19 for i := 0; i < len(s); i++ {
20 c := s[i]
21 if c < '0' || c > '9' {
22 return 0, false
23 }
24 n = n*10 + int64(c-'0')
25 }
26 return n, true
27}