From 3915d13b8d60723843a6d2a370e9547aa53a7165 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 18 Dec 2020 18:18:16 +0200 Subject: [PATCH] doc: update obsolete string(x)/string(x,len) to .vstring() and .vstring_with_len(len) --- doc/docs.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index 36e3e01807..8cf8808766 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -2854,11 +2854,12 @@ For example: `-cc gcc-9 -cflags -fsanitize=thread`. ### C types -Ordinary zero terminated C strings can be converted to V strings with `string(cstring)` -or `string(cstring, len)`. +Ordinary zero terminated C strings can be converted to V strings with +`unsafe { charptr(cstring).vstring() }` or if you know their length already with +`unsafe { charptr(cstring).vstring_with_len(len) }`. -NB: Each `string(...)` function does NOT create a copy of the `cstring`, -so you should NOT free it after calling `string()`. +NB: The .vstring() and .vstring_with_len() methods do NOT create a copy of the `cstring`, +so you should NOT free it after calling the method `.vstring()`. If you need to make a copy of the C string (some libc APIs like `getenv` pretty much require that, since they return pointers to internal libc memory), you can use `cstring_to_vstring(cstring)`.