implement missing string to int type methods (#1210)

* implement missing string to int methods

* make number base auto detected
pull/1216/head
joe-conigliaro 2019-07-18 04:11:14 +10:00 committed by Alexander Medvednikov
parent 7dc7502fe2
commit 8cd1f962d3
1 changed files with 16 additions and 0 deletions

View File

@ -133,6 +133,10 @@ pub fn (s string) int() int {
return C.atoi(s.str)
}
pub fn (s string) i32() i32 {
return C.atol(s.str)
}
pub fn (s string) i64() i64 {
return C.atoll(s.str)
}
@ -141,6 +145,18 @@ pub fn (s string) f32() f32 {
return C.atof(s.str)
}
pub fn (s string) f64() f64 {
return C.atof(s.str)
}
pub fn (s string) u32() u32 {
return C.strtoul(s.str, 0, 0)
}
pub fn (s string) u64() u64 {
return C.strtoull(s.str, 0, 0)
}
// ==
fn (s string) eq(a string) bool {
if isnil(s.str) {