fix number extraction ending with number
This commit is contained in:
1 parent
932e644c93
commit
225bd5b49c
2 files changed
+14
-5
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user