string: remove strconv dep

pull/2606/head
Alexander Medvednikov 2019-10-31 21:50:11 +03:00
parent 128d37c671
commit 4c96ca4e62
1 changed files with 50 additions and 4 deletions

View File

@ -4,6 +4,8 @@
module builtin
//import strconv
/*
NB: A V string should be/is immutable from the point of view of
V user programs after it is first created. A V string is
@ -41,7 +43,6 @@ NB: A V string should be/is immutable from the point of view of
when used with modules using C functions (for example os and so on).
*/
//import strconv
pub struct string {
//mut:
@ -202,8 +203,23 @@ pub fn (s string) int() int {
pub fn (s string) i64() i64 {
mut neg := false
mut i := 0
if s[0] == `-` {
neg = true
i++
}
else if s[0] == `+` {
i++
}
mut n := i64(0)
for C.isdigit(s[i]) {
n = i64(10) * n - i64(s[i] - `0`)
i++
}
return if neg { n } else { -n }
//return strconv.parse_int(s, 0, 64)
return C.atoll(*char(s.str))
//return C.atoll(*char(s.str))
}
pub fn (s string) f32() f32 {
@ -215,12 +231,42 @@ pub fn (s string) f64() f64 {
}
pub fn (s string) u32() u32 {
return C.atol(*char(s.str))
mut neg := false
mut i := 0
if s[0] == `-` {
neg = true
i++
}
else if s[0] == `+` {
i++
}
mut n := u32(0)
for C.isdigit(s[i]) {
n = u32(10) * n - u32(s[i] - `0`)
i++
}
return if neg { n } else { -n }
//return C.atol(*char(s.str))
//return strconv.parse_uint(s, 0, 32)
}
pub fn (s string) u64() u64 {
return C.atoll(*char(s.str))
mut neg := false
mut i := 0
if s[0] == `-` {
neg = true
i++
}
else if s[0] == `+` {
i++
}
mut n := u64(0)
for C.isdigit(s[i]) {
n = u64(10) * n - u64(s[i] - `0`)
i++
}
return if neg { n } else { -n }
//return C.atoll(*char(s.str))
//return strconv.parse_uint(s, 0, 64)
}