1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

implement missing string to int type methods (#1210)

* implement missing string to int methods

* make number base auto detected
This commit is contained in:
joe-conigliaro 2019-07-18 04:11:14 +10:00 committed by Alexander Medvednikov
parent 7dc7502fe2
commit 8cd1f962d3

View File

@ -133,6 +133,10 @@ pub fn (s string) int() int {
return C.atoi(s.str) return C.atoi(s.str)
} }
pub fn (s string) i32() i32 {
return C.atol(s.str)
}
pub fn (s string) i64() i64 { pub fn (s string) i64() i64 {
return C.atoll(s.str) return C.atoll(s.str)
} }
@ -141,6 +145,18 @@ pub fn (s string) f32() f32 {
return C.atof(s.str) 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 { fn (s string) eq(a string) bool {
if isnil(s.str) { if isnil(s.str) {