self
a well-formed Integer (i.e. parsable via to_i
)assert "123".is_int
assert "0b1011".is_int
assert "-34".is_int
assert "+45".is_int
assert not "0x_".is_int
assert not "0xGE".is_int
assert not "".is_int
assert not "Not an Int".is_int
assert not "-".is_int
# Is `self` a well-formed Integer (i.e. parsable via `to_i`)
#
# assert "123".is_int
# assert "0b1011".is_int
# assert "-34".is_int
# assert "+45".is_int
# assert not "0x_".is_int
# assert not "0xGE".is_int
# assert not "".is_int
# assert not "Not an Int".is_int
# assert not "-".is_int
fun is_int: Bool do
if byte_length == 0 then return false
var s = remove_all('_')
var pos = 0
var len = s.length
while pos < len and (s[pos] == '-' or s[pos] == '+') do
pos += 1
end
s = s.substring_from(pos)
var rets = s.strip_numhead
if rets == "" then return false
var hd = get_numhead
if hd == "0x" or hd == "0X" then return rets.is_hex
if hd == "0b" or hd == "0B" then return rets.is_bin
if hd == "0o" or hd == "0O" then return rets.is_oct
return rets.is_dec
end
lib/core/text/fixed_ints_text.nit:207,2--234,4