fix number extraction ending with number

This commit is contained in:
Gokcehan committed 2016-12-03 00:38:23 +03:00
1 parent 932e644c93
commit 225bd5b49c
2 files changed
+14 -5

No files matched your search

+12 -5
View File
@@ -191,18 +191,15 @@ func extractNums(s string) (nums []int, rest []string, numFirst bool) {
digit := unicode.IsDigit(r)
numFirst = digit
for i, c := range s {
for _, c := range s {
if unicode.IsDigit(c) == digit {
buf = append(buf, c)
if i != len(s)-1 {
continue
}
continue
}
if digit {
i, err := strconv.Atoi(string(buf))
if err != nil {
// TODO: handle error
log.Printf("extracting numbers: %s", err)
}
nums = append(nums, i)
@@ -215,6 +212,16 @@ func extractNums(s string) (nums []int, rest []string, numFirst bool) {
digit = !digit
}
if digit {
i, err := strconv.Atoi(string(buf))
if err != nil {
log.Printf("extracting numbers: %s", err)
}
nums = append(nums, i)
} else {
rest = append(rest, string(buf))
}
return
}