string: remove strconv dep
parent
128d37c671
commit
4c96ca4e62
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
module builtin
|
module builtin
|
||||||
|
|
||||||
|
//import strconv
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NB: A V string should be/is immutable from the point of view of
|
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
|
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).
|
when used with modules using C functions (for example os and so on).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//import strconv
|
|
||||||
|
|
||||||
pub struct string {
|
pub struct string {
|
||||||
//mut:
|
//mut:
|
||||||
|
@ -202,8 +203,23 @@ pub fn (s string) int() int {
|
||||||
|
|
||||||
|
|
||||||
pub fn (s string) i64() i64 {
|
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 strconv.parse_int(s, 0, 64)
|
||||||
return C.atoll(*char(s.str))
|
//return C.atoll(*char(s.str))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s string) f32() f32 {
|
pub fn (s string) f32() f32 {
|
||||||
|
@ -215,12 +231,42 @@ pub fn (s string) f64() f64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s string) u32() u32 {
|
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)
|
//return strconv.parse_uint(s, 0, 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (s string) u64() u64 {
|
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)
|
//return strconv.parse_uint(s, 0, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue