mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: move C. calls to .c.v files (#11164)
This commit is contained in:
@@ -55,12 +55,6 @@ mut:
|
||||
is_lit int
|
||||
}
|
||||
|
||||
// vstrlen returns the V length of the C string `s` (0 terminator is not counted).
|
||||
[unsafe]
|
||||
pub fn vstrlen(s &byte) int {
|
||||
return unsafe { C.strlen(&char(s)) }
|
||||
}
|
||||
|
||||
pub fn (s string) runes() []rune {
|
||||
mut runes := []rune{cap: s.len}
|
||||
for i := 0; i < s.len; i++ {
|
||||
@@ -118,7 +112,7 @@ pub fn tos3(s &char) string {
|
||||
}
|
||||
return string{
|
||||
str: &byte(s)
|
||||
len: unsafe { C.strlen(s) }
|
||||
len: unsafe { vstrlen_char(s) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +141,7 @@ pub fn tos5(s &char) string {
|
||||
pub fn (bp &byte) vstring() string {
|
||||
return string{
|
||||
str: unsafe { bp }
|
||||
len: unsafe { C.strlen(&char(bp)) }
|
||||
len: unsafe { vstrlen(bp) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +162,7 @@ pub fn (bp &byte) vstring_with_len(len int) string {
|
||||
pub fn (cp &char) vstring() string {
|
||||
return string{
|
||||
str: &byte(cp)
|
||||
len: unsafe { C.strlen(cp) }
|
||||
len: unsafe { vstrlen_char(cp) }
|
||||
is_lit: 0
|
||||
}
|
||||
}
|
||||
@@ -195,7 +189,7 @@ pub fn (cp &char) vstring_with_len(len int) string {
|
||||
pub fn (bp &byte) vstring_literal() string {
|
||||
return string{
|
||||
str: unsafe { bp }
|
||||
len: unsafe { C.strlen(&char(bp)) }
|
||||
len: unsafe { vstrlen(bp) }
|
||||
is_lit: 1
|
||||
}
|
||||
}
|
||||
@@ -218,7 +212,7 @@ pub fn (bp &byte) vstring_literal_with_len(len int) string {
|
||||
pub fn (cp &char) vstring_literal() string {
|
||||
return string{
|
||||
str: &byte(cp)
|
||||
len: unsafe { C.strlen(cp) }
|
||||
len: unsafe { vstrlen_char(cp) }
|
||||
is_lit: 1
|
||||
}
|
||||
}
|
||||
@@ -251,7 +245,7 @@ pub fn (a string) clone() string {
|
||||
len: a.len
|
||||
}
|
||||
unsafe {
|
||||
C.memcpy(b.str, a.str, a.len)
|
||||
vmemcpy(b.str, a.str, a.len)
|
||||
b.str[a.len] = 0
|
||||
}
|
||||
return b
|
||||
@@ -453,13 +447,11 @@ pub fn (s string) i16() i16 {
|
||||
|
||||
// f32 returns the value of the string as f32 `'1.0'.f32() == f32(1)`.
|
||||
pub fn (s string) f32() f32 {
|
||||
// return C.atof(&char(s.str))
|
||||
return f32(strconv.atof64(s))
|
||||
}
|
||||
|
||||
// f64 returns the value of the string as f64 `'1.0'.f64() == f64(1)`.
|
||||
pub fn (s string) f64() f64 {
|
||||
// return C.atof(&char(s.str))
|
||||
return strconv.atof64(s)
|
||||
}
|
||||
|
||||
@@ -494,7 +486,7 @@ fn (s string) == (a string) bool {
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
return C.memcmp(s.str, a.str, a.len) == 0
|
||||
return vmemcmp(s.str, a.str, a.len) == 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1411,13 +1403,13 @@ pub fn (a []string) join(sep string) string {
|
||||
mut idx := 0
|
||||
for i, val in a {
|
||||
unsafe {
|
||||
C.memcpy(res.str + idx, val.str, val.len)
|
||||
vmemcpy(res.str + idx, val.str, val.len)
|
||||
idx += val.len
|
||||
}
|
||||
// Add sep if it's not last
|
||||
if i != a.len - 1 {
|
||||
unsafe {
|
||||
C.memcpy(res.str + idx, sep.str, sep.len)
|
||||
vmemcpy(res.str + idx, sep.str, sep.len)
|
||||
idx += sep.len
|
||||
}
|
||||
}
|
||||
@@ -1482,7 +1474,7 @@ pub fn (s string) bytes() []byte {
|
||||
return []
|
||||
}
|
||||
mut buf := []byte{len: s.len}
|
||||
unsafe { C.memcpy(buf.data, s.str, s.len) }
|
||||
unsafe { vmemcpy(buf.data, s.str, s.len) }
|
||||
return buf
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user