mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
string: make substr() copy the data, like in Java and C#; remove .cstr()
this makes managing memory used by strings much easier V strings are now fully compatible with C strings
This commit is contained in:
@@ -29,9 +29,9 @@ fn download_file_with_progress(url, out string, cb downloadfn, cb_finished downl
|
||||
if isnil(curl) {
|
||||
return
|
||||
}
|
||||
cout := out.cstr()
|
||||
cout := out.str
|
||||
fp := C.fopen(cout, 'wb')
|
||||
C.curl_easy_setopt(curl, CURLOPT_URL, url.cstr())
|
||||
C.curl_easy_setopt(curl, CURLOPT_URL, url.str)
|
||||
C.curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, download_cb)
|
||||
data := &DownloadStruct {
|
||||
stream:fp
|
||||
|
@@ -104,7 +104,7 @@ pub fn (req &Request) do() Response {
|
||||
}
|
||||
// options
|
||||
// url2 := req.url.clone()
|
||||
C.curl_easy_setopt(curl, CURLOPT_URL, req.url.cstr())// ..clone())
|
||||
C.curl_easy_setopt(curl, CURLOPT_URL, req.url.str)// ..clone())
|
||||
// C.curl_easy_setopt(curl, CURLOPT_URL, 'http://example.com')
|
||||
// return resp
|
||||
// curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
@@ -117,7 +117,7 @@ pub fn (req &Request) do() Response {
|
||||
C.curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hchunk)
|
||||
C.curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1)
|
||||
if req.typ == 'POST' {
|
||||
C.curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req.data.cstr())
|
||||
C.curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req.data.str)
|
||||
C.curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, 'POST')
|
||||
// req.headers << 'Content-Type: application/x-www-form-urlencoded'
|
||||
}
|
||||
@@ -126,7 +126,7 @@ pub fn (req &Request) do() Response {
|
||||
// for i, h := range req.headers {
|
||||
for key, val in req.headers {
|
||||
h := '$key: $val'
|
||||
hlist = C.curl_slist_append(hlist, h.cstr())
|
||||
hlist = C.curl_slist_append(hlist, h.str)
|
||||
}
|
||||
// curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, // (long)CURL_HTTP_VERSION_2TLS);<3B>`C<>ʀ9<CA80>
|
||||
C.curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1)
|
||||
@@ -190,11 +190,11 @@ pub fn (req &Request) do() Response {
|
||||
}
|
||||
|
||||
fn unescape(s string) string {
|
||||
return string(byteptr(C.curl_unescape(s.cstr(), s.len)))
|
||||
return string(byteptr(C.curl_unescape(s.str, s.len)))
|
||||
}
|
||||
|
||||
fn escape(s string) string {
|
||||
return string(byteptr(C.curl_escape(s.cstr(), s.len)))
|
||||
return string(byteptr(C.curl_escape(s.str, s.len)))
|
||||
}
|
||||
|
||||
// ////////////////
|
||||
|
Reference in New Issue
Block a user