Returns self as the corresponding integer

assert "123".to_i        == 123
assert "-1".to_i         == -1
assert "0x64".to_i       == 100
assert "0b1100_0011".to_i== 195
assert "--12".to_i       == 12
assert "+45".to_i        == 45

REQUIRE: self.is_int

Property definitions

core $ Text :: to_i
	# Returns `self` as the corresponding integer
	#
	# ~~~
	# assert "123".to_i        == 123
	# assert "-1".to_i         == -1
	# assert "0x64".to_i       == 100
	# assert "0b1100_0011".to_i== 195
	# assert "--12".to_i       == 12
	# assert "+45".to_i        == 45
	# ~~~
	#
	# REQUIRE: `self`.`is_int`
	fun to_i: Int is abstract
lib/core/text/abstract_text.nit:248,2--260,26

core :: fixed_ints_text $ Text :: to_i
	redef fun to_i
	do
		assert self.is_int
		var s = remove_all('_')
		var val = 0
		var neg = false
		var pos = 0
		loop
			if s[pos] == '-' then
				neg = not neg
				pos += 1
			else if s[pos] == '+' then
				pos += 1
			else
				break
			end
		end
		s = s.substring_from(pos)
		if s.length >= 2 then
			var s1 = s[1]
			if s1 == 'x' or s1 == 'X' then
				val = s.substring_from(2).to_hex
			else if s1 == 'o' or s1 == 'O' then
				val = s.substring_from(2).to_oct
			else if s1 == 'b' or s1 == 'B' then
				val = s.substring_from(2).to_bin
			else if s1.is_numeric then
				val = s.to_dec
			end
		else
			val = s.to_dec
		end
		return if neg then -val else val
	end
lib/core/text/fixed_ints_text.nit:236,2--269,4