Skip to content

Commit

Permalink
Fix isNumber to only accept numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
drt24 committed Jul 13, 2016
1 parent 7c3cf72 commit bf3c320
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"github.com/awalterschulze/gographviz/scanner"
"github.com/awalterschulze/gographviz/token"
"regexp"
"strings"
"text/template"
"unicode"
Expand Down Expand Up @@ -85,26 +86,10 @@ func isDigit(ch rune) bool {
return '0' <= ch && ch <= '9' || ch >= 0x80 && unicode.IsDigit(ch)
}

var numeral = regexp.MustCompile("-?((.[2-9]+)|([0-9]+(.[0-9]*)?))")

func isNumber(s string) bool {
state := 0
for _, c := range s {
if state == 0 {
if isDigit(c) || c == '.' {
state = 2
} else if c == '-' {
state = 1
} else {
return false
}
} else if state == 1 {
if isDigit(c) || c == '.' {
state = 2
}
} else if c != '.' && !isDigit(c) {
return false
}
}
return (state == 2)
return numeral.MatchString(s)
}

func isStringLit(s string) bool {
Expand Down

0 comments on commit bf3c320

Please sign in to comment.