MCPcopy Create free account
hub / github.com/github/gh-aw / IsPositiveInteger

Function IsPositiveInteger

pkg/stringutil/stringutil.go:150–164  ·  view source on GitHub ↗

IsPositiveInteger checks if a string is a positive integer. Returns true for strings like "1", "123", "999" but false for: - Zero ("0") - Negative numbers ("-5") - Numbers with leading zeros ("007") - Floating point numbers ("3.14") - Non-numeric strings ("abc") - Empty strings ("")

(s string)

Source from the content-addressed store, hash-verified

148// - Non-numeric strings ("abc")
149// - Empty strings ("")
150func IsPositiveInteger(s string) bool {
151 // Must not be empty
152 if s == "" {
153 return false
154 }
155
156 // Must not have leading zeros (except "0" itself, but that's not positive)
157 if len(s) > 1 && s[0] == '0' {
158 return false
159 }
160
161 // Must be numeric and > 0
162 num, err := strconv.ParseInt(s, 10, 64)
163 return err == nil && num > 0
164}

Callers 3

validateTargetValueFunction · 0.92
TestIsPositiveIntegerFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestIsPositiveIntegerFunction · 0.68