Skip to content

builtin #

Constants #

const (
	si_s_code   = '0xfe10'
	si_g32_code = '0xfe0e'
	si_g64_code = '0xfe0f'
)

substitute old _STR calls

fn c_error_number_str #

fn c_error_number_str(errnum int) string

return a C-API error message matching to errnum

fn compare_strings #

fn compare_strings(a &string, b &string) int

compare_strings returns -1 if a < b, 1 if a > b else 0.

fn copy #

fn copy(dst []byte, src []byte) int

copy copies the src byte array elements to the dst byte array.
The number of the elements copied is the minimum of the length of both arrays.
Returns the number of elements copied.
TODO: implement for all types

fn cstring_to_vstring #

unsafe
fn cstring_to_vstring(s &char) string

cstring_to_vstring creates a new V string copy of the C style string, pointed by s. This function is most likely what you want to use when working with C style pointers to 0 terminated strings (i.e. char*).
It is recomended to use it, unless you do understand the implications of tos/tos2/tos3/tos4/tos5 in terms of memory management and interactions with -autofree and [manualfree].
It will panic, if the pointer s is 0.

fn eprint #

fn eprint(s string)

eprint prints a message to stderr. Both stderr and stdout are flushed.

fn eprintln #

fn eprintln(s string)

eprintln prints a message with a line end, to stderr. Both stderr and stdout are flushed.

fn error #

fn error(message string) IError

error returns a default error instance containing the error given in message.

Example

`if ouch { return error('an error occurred') }`

fn error_with_code #

fn error_with_code(message string, code int) IError

error_with_code returns a default error instance containing the given message and error code.
if ouch { return error_with_code('an error occurred', 1) }

fn exit #

fn exit(code int)

exit terminates execution immediately and returns exit code to the shell.

fn f32_abs #

fn f32_abs(a f32) f32

f32_abs returns the absolute value of a as a f32 value.

Example

assert f32_abs(-2.0) == 2.0

fn f32_max #

fn f32_max(a f32, b f32) f32

f32_max returns the largest f32 of input a and b.

Example

assert f32_max(2.0,3.0) == 3.0

fn f32_min #

fn f32_min(a f32, b f32) f32

f32_min returns the smallest f32 of input a and b.

Example

assert f32_min(2.0,3.0) == 2.0

fn f64_max #

fn f64_max(a f64, b f64) f64

f64_max returns the largest f64 of input a and b.

Example

assert f64_max(2.0,3.0) == 3.0

fn free #

unsafe
fn free(ptr voidptr)

free allows for manually freeing memory allocated at the address ptr.

fn gc_check_leaks #

fn gc_check_leaks()

fn get_str_intp_u32_format #

fn get_str_intp_u32_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch byte, in_base int, in_upper_case bool) u32

convert from data format to compact u32

fn get_str_intp_u64_format #

fn get_str_intp_u64_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch byte, in_base int, in_upper_case bool) u64

convert from data format to compact u64

fn isnil #

fn isnil(v voidptr) bool

isnil returns true if an object is nil (only for C objects).

fn malloc #

unsafe
fn malloc(n int) &byte

malloc dynamically allocates a n bytes block of memory on the heap.
malloc returns a byteptr pointing to the memory address of the allocated space.
unlike the calloc family of functions - malloc will not zero the memory block.

fn malloc_noscan #

unsafe
fn malloc_noscan(n int) &byte

fn memdup #

unsafe
fn memdup(src voidptr, sz int) voidptr

memdup dynamically allocates a sz bytes block of memory on the heap memdup then copies the contents of src into the allocated space and returns a pointer to the newly allocated space.

fn memdup_noscan #

unsafe
fn memdup_noscan(src voidptr, sz int) voidptr

fn panic #

fn panic(s string)

panic prints a nice error message, then exits the process with exit code of 1.
It also shows a backtrace on most platforms.

fn panic_error_number #

fn panic_error_number(basestr string, errnum int)

panic with a C-API error message matching errnum

fn panic_lasterr #

fn panic_lasterr()

fn panic_optional_not_set #

fn panic_optional_not_set(s string)

fn print #

fn print(s string)

print prints a message to stdout. Unlike println stdout is not automatically flushed.
A call to flush() will flush the output buffer to stdout.

fn println #

fn println(s string)

println prints a message with a line end, to stdout. stdout is flushed.

fn proc_pidpath #

fn proc_pidpath(int, voidptr, int) int

fn ptr_str #

fn ptr_str(ptr voidptr) string

ptr_str returns the address of ptr as a string.

fn realloc_data #

unsafe
fn realloc_data(old_data &byte, old_size int, new_size int) &byte

realloc_data resizes the memory block pointed by old_data to new_size bytes. old_data must be a pointer to an existing memory block, previously allocated with malloc, v_calloc or vcalloc, of size old_data.
realloc_data returns a pointer to the new location of the block.
NB: if you know the old data size, it is preferable to call realloc_data, instead of v_realloc, at least during development, because realloc_data can make debugging easier, when you compile your program with -d debug_realloc.

fn str_intp #

fn str_intp(data_len int, in_data voidptr) string

interpolation function

fn str_intp_g32 #

fn str_intp_g32(in_str string) string

fn str_intp_g64 #

fn str_intp_g64(in_str string) string

fn str_intp_rune #

fn str_intp_rune(in_str string) string

fn str_intp_sq #

fn str_intp_sq(in_str string) string

fn str_intp_sub #

fn str_intp_sub(base_str string, in_str string) string

replace %% with the in_str

fn string_from_wide #

unsafe
fn string_from_wide(_wstr &u16) string

fn string_from_wide2 #

unsafe
fn string_from_wide2(_wstr &u16, len int) string

fn tos #

unsafe
fn tos(s &byte, len int) string

tos creates a V string, given a C style pointer to a 0 terminated block.
NB: the memory block pointed by s is reused, not copied! It will panic, when the pointer s is 0.
See also tos_clone.

fn tos2 #

unsafe
fn tos2(s &byte) string

tos2 creates a V string, given a C style pointer to a 0 terminated block.
NB: the memory block pointed by s is reused, not copied! It will calculate the length first, thus it is more costly than tos.
It will panic, when the pointer s is 0.
It is the same as tos3, but for &byte pointers, avoiding callsite casts.
See also tos_clone.

fn tos3 #

unsafe
fn tos3(s &char) string

tos3 creates a V string, given a C style pointer to a 0 terminated block.
NB: the memory block pointed by s is reused, not copied! It will calculate the length first, so it is more costly than tos.
It will panic, when the pointer s is 0.
It is the same as tos2, but for &char pointers, avoiding callsite casts.
See also tos_clone.

fn tos4 #

unsafe
fn tos4(s &byte) string

tos4 creates a V string, given a C style pointer to a 0 terminated block.
NB: the memory block pointed by s is reused, not copied! It will calculate the length first, so it is more costly than tos.
It returns '', when given a 0 pointer s, it does NOT panic.
It is the same as tos5, but for &byte pointers, avoiding callsite casts.
See also tos_clone.

fn tos5 #

unsafe
fn tos5(s &char) string

tos5 creates a V string, given a C style pointer to a 0 terminated block.
NB: the memory block pointed by s is reused, not copied! It will calculate the length first, so it is more costly than tos.
It returns '', when given a 0 pointer s, it does NOT panic.
It is the same as tos4, but for &char pointers, avoiding callsite casts.
See also tos_clone.

fn tos_clone #

unsafe
fn tos_clone(s &byte) string

tos_clone creates a new V string copy of the C style string, pointed by s.
See also cstring_to_vstring (it is the same as it, the only difference is, that tos_clone expects &byte, while cstring_to_vstring expects &char).
It will panic, if the pointer s is 0.

fn utf32_to_str #

fn utf32_to_str(code u32) string

Convert utf32 to utf8 utf32 == Codepoint

fn utf32_to_str_no_malloc #

unsafe
fn utf32_to_str_no_malloc(code u32, buf &byte) string

fn utf8_char_len #

fn utf8_char_len(b byte) int

fn utf8_getchar #

fn utf8_getchar() int

Reads an utf8 character from standard input

fn utf8_str_len #

fn utf8_str_len(s string) int

Calculate string length for in number of codepoints

fn utf8_str_visible_length #

fn utf8_str_visible_length(s string) int

Calculate string length for formatting, i.e. number of "characters" This is simplified implementation. if you need specification compliant width, use utf8.east_asian.display_width.

fn v_realloc #

unsafe
fn v_realloc(b &byte, n int) &byte

v_realloc resizes the memory block b with n bytes.
The b byteptr must be a pointer to an existing memory block previously allocated with malloc, v_calloc or vcalloc.
Please, see also realloc_data, and use it instead if possible.

fn vcalloc #

fn vcalloc(n int) &byte

vcalloc dynamically allocates a zeroed n bytes block of memory on the heap.
vcalloc returns a byteptr pointing to the memory address of the allocated space.
Unlike v_calloc vcalloc checks for negative values given in n.

fn vcalloc_noscan #

fn vcalloc_noscan(n int) &byte

special versions of the above that allocate memory which is not scanned for pointers (but is collected) when the Boehm garbage collection is used

fn vmemcmp #

unsafe
fn vmemcmp(const_s1 voidptr, const_s2 voidptr, n int) int

vmemcmp compares the first n bytes (each interpreted as unsigned char) of the memory areas s1 and s2. It returns an integer less than, equal to, or greater than zero, if the first n bytes of s1 is found, respectively, to be less than, to match, or be greater than the first n bytes of s2.
For a nonzero return value, the sign is determined by the sign of the difference between the first pair of bytes (interpreted as unsigned char) that differ in s1 and s2.
If n is zero, the return value is zero.
Do NOT use vmemcmp to compare security critical data, such as cryptographic secrets, because the required CPU time depends on the number of equal bytes.
You should use a function that performs comparisons in constant time for this.

fn vmemcpy #

unsafe
fn vmemcpy(dest voidptr, const_src voidptr, n int) voidptr

vmemcpy copies n bytes from memory area src to memory area dest.
The memory areas MUST NOT OVERLAP. Use vmemmove, if the memory areas do overlap. vmemcpy returns a pointer to dest.

fn vmemmove #

unsafe
fn vmemmove(dest voidptr, const_src voidptr, n int) voidptr

vmemmove copies n bytes from memory area src to memory area dest.
The memory areas MAY overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dest, and the bytes are then copied from the temporary array to dest. vmemmove returns a pointer to dest.

fn vmemset #

unsafe
fn vmemset(s voidptr, c int, n int) voidptr

vmemset fills the first n bytes of the memory area pointed to by s, with the constant byte c. It returns a pointer to the memory area s.

fn vstrlen #

unsafe
fn vstrlen(s &byte) int

vstrlen returns the V length of the C string s (0 terminator is not counted).
The C string is expected to be a &byte pointer.

fn vstrlen_char #

unsafe
fn vstrlen_char(s &char) int

vstrlen_char returns the V length of the C string s (0 terminator is not counted).
The C string is expected to be a &char pointer.

fn winapi_lasterr_str #

fn winapi_lasterr_str() string

These functions are Windows specific - provide dummys for *nix

interface IError #

interface IError {
	msg string
	code int
}

IError holds information about an error instance

fn (IError) free #

unsafe
fn (ie &IError) free()

fn (IError) str #

fn (err IError) str() string

fn ([]byte) bytestr #

fn (b []byte) bytestr() string

bytestr produces a string from all the bytes in the array.
NB: the returned string will have .len equal to the array.len, even when some of the array bytes were 0.
If you want to get a V string, that contains only the bytes till the first 0 byte, use tos_clone(&byte(array.data)) instead.

fn ([]byte) clone #

fn (b []byte) clone() []byte

clone clones the byte array, and returns the newly created copy.

fn ([]byte) hex #

fn (b []byte) hex() string

hex returns a string with the hexadecimal representation of the byte elements of the array.

fn ([]int) reduce #

fn (a []int) reduce(iter fn (int, int) int, accum_start int) int

reduce executes a given reducer function on each element of the array, resulting in a single output value.

fn ([]rune) string #

fn (ra []rune) string() string

string converts a rune array to a string

fn ([]string) free #

unsafe
fn (mut a []string) free()

fn ([]string) join #

fn (a []string) join(sep string) string

join joins a string array into a string using sep separator.

Example

assert ['Hello','V'].join(' ') == 'Hello V'

fn ([]string) join_lines #

fn (s []string) join_lines() string

join joins a string array into a string using a \n newline delimiter.

fn ([]string) sort_by_len #

fn (mut s []string) sort_by_len()

sort_by_len sorts the the string array by each string's .len length.

fn ([]string) sort_ignore_case #

fn (mut s []string) sort_ignore_case()

sort_ignore_case sorts the string array using case insesitive comparing.

fn ([]string) str #

fn (a []string) str() string

str returns a string representation of the array of strings => '["a", "b", "c"]'.

fn (bool) str #

fn (b bool) str() string

str returns the value of the bool as a string.

Example

assert (2 > 1).str() == 'true'

fn (byte) ascii_str #

fn (b byte) ascii_str() string

ascii_str returns the contents of byte as a zero terminated ASCII string character.

Example

assert byte(97).ascii_str() == 'a'

fn (byte) hex #

fn (nn byte) hex() string

hex returns the value of the byte as a hexadecimal string.
Note that the output is zero padded for values below 16.

Examples

assert byte(2).hex() == '02'
assert byte(15).hex() == '0f'
assert byte(255).hex() == 'ff'

fn (byte) hex_full #

fn (nn byte) hex_full() string

fn (byte) is_alnum #

fn (c byte) is_alnum() bool

is_alnum returns true if the byte is in range a-z, A-Z, 0-9 and false otherwise.

Example

assert byte(`V`) == true

fn (byte) is_bin_digit #

fn (c byte) is_bin_digit() bool

is_bin_digit returns true if the byte is a binary digit (0 or 1) and false otherwise.

Example

assert byte(`0`) == true

fn (byte) is_capital #

fn (c byte) is_capital() bool

is_capital returns true, if the byte is a Latin capital letter.

Examples

assert `H`.is_capital() == true
assert 'h`.is_capital() == false

fn (byte) is_digit #

fn (c byte) is_digit() bool

is_digit returns true if the byte is in range 0-9 and false otherwise.

Example

assert byte(`9`) == true

fn (byte) is_hex_digit #

fn (c byte) is_hex_digit() bool

is_hex_digit returns true if the byte is either in range 0-9, a-f or A-F and false otherwise.

Example

assert byte(`F`) == true

fn (byte) is_letter #

fn (c byte) is_letter() bool

is_letter returns true if the byte is in range a-z or A-Z and false otherwise.

Example

assert byte(`V`) == true

fn (byte) is_oct_digit #

fn (c byte) is_oct_digit() bool

is_oct_digit returns true if the byte is in range 0-7 and false otherwise.

Example

assert byte(`7`) == true

fn (byte) is_space #

fn (c byte) is_space() bool

is_space returns true if the byte is a white space character.
The following list is considered white space characters: , \t, \n, \v, \f, \r, 0x85, 0xa0

Example

assert byte(` `).is_space() == true

fn (byte) repeat #

fn (b byte) repeat(count int) string

repeat returns a new string with count number of copies of the byte it was called on.

fn (byte) str #

fn (b byte) str() string

str returns the contents of byte as a zero terminated string.

Example

assert byte(111).str() == '111'

fn (byte) str_escaped #

fn (b byte) str_escaped() string

str_escaped returns the contents of byte as an escaped string.

Example

assert byte(0).str_escaped() == r'`\0`'

fn (byte) vbytes #

unsafe
fn (data &byte) vbytes(len int) []byte

byteptr.vbytes() - makes a V []byte structure from a C style memory buffer. NB: the data is reused, NOT copied!

fn (byte) vstring #

unsafe
fn (bp &byte) vstring() string

vstring converts a C style string to a V string.
NB: the memory block pointed by bp is reused, not copied! NB: instead of &byte(arr.data).vstring(), do use tos_clone(&byte(arr.data)).
Strings returned from this function will be normal V strings beside that, (i.e. they would be freed by V's -autofree mechanism, when they are no longer used).
See also tos_clone.

fn (byte) vstring_literal #

unsafe
fn (bp &byte) vstring_literal() string

vstring_literal converts a C style string to a V string.
NB: the memory block pointed by bp is reused, not copied! NB2: unlike vstring, vstring_literal will mark the string as a literal, so it will not be freed by -autofree.
This is suitable for readonly strings, C string literals etc, that can be read by the V program, but that should not be managed/freed by it, for example os.args is implemented using it.
See also tos_clone.

fn (byte) vstring_literal_with_len #

unsafe
fn (bp &byte) vstring_literal_with_len(len int) string

vstring_with_len converts a C style string to a V string.
NB: the memory block pointed by bp is reused, not copied! This method has lower overhead compared to .vstring_literal(), since it does not need to calculate the length of the 0 terminated string.
See also tos_clone.

fn (byte) vstring_with_len #

unsafe
fn (bp &byte) vstring_with_len(len int) string

vstring_with_len converts a C style 0 terminated string to a V string.
NB: the memory block pointed by bp is reused, not copied! This method has lower overhead compared to .vstring(), since it does not need to calculate the length of the 0 terminated string.
See also tos_clone.

fn (byteptr) str #

fn (nn byteptr) str() string

hex returns the value of the byteptr as a hexadecimal string.
Note that the output is not zero padded.
pub fn (nn byteptr) str() string {

fn (byteptr) vbytes #

unsafe
fn (data byteptr) vbytes(len int) []byte

byteptr.vbytes() - makes a V []byte structure from a C style memory buffer. NB: the data is reused, NOT copied!

fn (byteptr) vstring #

unsafe
fn (bp byteptr) vstring() string

vstring converts a C style string to a V string. NB: the string data is reused, NOT copied.
strings returned from this function will be normal V strings beside that (i.e. they would be freed by V's -autofree mechanism, when they are no longer used).

fn (byteptr) vstring_literal #

unsafe
fn (bp byteptr) vstring_literal() string

vstring_literal converts a C style string to a V string.
NB: the string data is reused, NOT copied.
NB2: unlike vstring, vstring_literal will mark the string as a literal, so it will not be freed by autofree.
This is suitable for readonly strings, C string literals etc, that can be read by the V program, but that should not be managed by it, for example os.args is implemented using it.

fn (byteptr) vstring_literal_with_len #

unsafe
fn (bp byteptr) vstring_literal_with_len(len int) string

vstring_with_len converts a C style string to a V string.
NB: the string data is reused, NOT copied.

fn (byteptr) vstring_with_len #

unsafe
fn (bp byteptr) vstring_with_len(len int) string

vstring_with_len converts a C style string to a V string.
NB: the string data is reused, NOT copied.

fn (chan) close #

fn (ch chan) close()

close closes the channel for further push transactions.
closed channels cannot be pushed to, however they can be popped from as long as there is still objects available in the channel buffer.

fn (chan) try_pop #

fn (ch chan) try_pop(obj voidptr) ChanState

try_pop returns ChanState.success if an object is popped from the channel.
try_pop effectively pops from the channel without waiting for objects to become available.
Both the test and pop transaction is done atomically.

fn (chan) try_push #

fn (ch chan) try_push(obj voidptr) ChanState

try_push returns ChanState.success if the object is pushed to the channel.
try_push effectively both push and test if the transaction ch <- a succeeded.
Both the test and push transaction is done atomically.

fn (char) str #

fn (cptr &char) str() string

fn (char) vstring #

unsafe
fn (cp &char) vstring() string

vstring converts a C style string to a V string.
NB: the memory block pointed by bp is reused, not copied! Strings returned from this function will be normal V strings beside that, (i.e. they would be freed by V's -autofree mechanism, when they are no longer used).
NB: instead of &byte(a.data).vstring(), use tos_clone(&byte(a.data)).
See also tos_clone.

fn (char) vstring_literal #

unsafe
fn (cp &char) vstring_literal() string

vstring_literal converts a C style string char* pointer to a V string.
NB: the memory block pointed by bp is reused, not copied! See also byteptr.vstring_literal for more details.
See also tos_clone.

fn (char) vstring_literal_with_len #

unsafe
fn (cp &char) vstring_literal_with_len(len int) string

vstring_literal_with_len converts a C style string char* pointer, to a V string.
NB: the memory block pointed by bp is reused, not copied! This method has lower overhead compared to .vstring_literal(), since it does not need to calculate the length of the 0 terminated string.
See also tos_clone.

fn (char) vstring_with_len #

unsafe
fn (cp &char) vstring_with_len(len int) string

vstring_with_len converts a C style 0 terminated string to a V string.
NB: the memory block pointed by bp is reused, not copied! This method has lower overhead compared to .vstring(), since it does not calculate the length of the 0 terminated string.
See also tos_clone.

fn (charptr) vstring #

unsafe
fn (cp charptr) vstring() string

vstring converts C char* to V string.
NB: the string data is reused, NOT copied.

fn (charptr) vstring_with_len #

unsafe
fn (cp charptr) vstring_with_len(len int) string

vstring_with_len converts C char* to V string.
NB: the string data is reused, NOT copied.

fn (charptr) vstring_literal #

unsafe
fn (cp charptr) vstring_literal() string

vstring_literal converts C char* to V string.
See also vstring_literal defined on byteptr for more details.
NB: the string data is reused, NOT copied.

fn (charptr) vstring_literal_with_len #

unsafe
fn (cp charptr) vstring_literal_with_len(len int) string

vstring_literal_with_len converts C char* to V string.
See also vstring_literal_with_len defined on byteptr.
NB: the string data is reused, NOT copied.

fn (f32) str #

fn (x f32) str() string

str returns a f32 as string in suitable notation.

fn (f32) strg #

fn (x f32) strg() string

strg return a f32 as string in "g" printf format

fn (f32) strsci #

fn (x f32) strsci(digit_num int) string

strsci returns the f32 as a string in scientific notation with digit_num deciamals displayed, max 8 digits.

Example

assert f32(1.234).strsci(3) == '1.234e+00'

fn (f32) strlong #

fn (x f32) strlong() string

strlong returns a decimal notation of the f32 as a string.

fn (f32) eq_epsilon #

fn (a f32) eq_epsilon(b f32) bool

eq_epsilon returns true if the f32 is equal to input b.
using an epsilon of typically 1E-5 or higher (backend/compiler dependent).

Example

assert f32(2.0).eq_epsilon(2.0)

fn (f64) str #

fn (x f64) str() string

str return a f64 as string in suitable notation.

fn (f64) strg #

fn (x f64) strg() string

strg return a f64 as string in "g" printf format

fn (f64) strsci #

fn (x f64) strsci(digit_num int) string

strsci returns the f64 as a string in scientific notation with digit_num decimals displayed, max 17 digits.

Example

assert f64(1.234).strsci(3) == '1.234e+00'

fn (f64) strlong #

fn (x f64) strlong() string

strlong returns a decimal notation of the f64 as a string.

Example

assert f64(1.23456).strlong() == '1.23456'

fn (f64) eq_epsilon #

fn (a f64) eq_epsilon(b f64) bool

eq_epsilon returns true if the f64 is equal to input b.
using an epsilon of typically 1E-9 or higher (backend/compiler dependent).

Example

assert f64(2.0).eq_epsilon(2.0)

fn (float literal) str #

fn (d float_literal) str() string

str returns the value of the float_literal as a string.

fn (i16) str #

fn (n i16) str() string

str returns the value of the i16 as a string.

Example

assert i16(-20).str() == '-20'

fn (i16) hex #

fn (nn i16) hex() string

hex returns the value of the i16 as a hexadecimal string.
Note that the output is not zero padded.

Examples

assert i16(2).hex() == '2'
assert i16(200).hex() == 'c8'

fn (i16) hex_full #

fn (nn i16) hex_full() string

fn (i64) str #

fn (nn i64) str() string

str returns the value of the i64 as a string.

Example

assert i64(-200000).str() == '-200000'

fn (i64) hex #

fn (nn i64) hex() string

hex returns the value of the i64 as a hexadecimal string.
Note that the output is not zero padded.

Examples

assert i64(2).hex() == '2'
assert i64(-200).hex() == 'ffffffffffffff38'
assert i64(2021).hex() == '7e5'

fn (i64) hex_full #

fn (nn i64) hex_full() string

fn (i8) str #

fn (n i8) str() string

str returns the value of the i8 as a string.

Example

assert i8(-2).str() == '-2'

fn (i8) hex #

fn (nn i8) hex() string

hex returns the value of the i8 as a hexadecimal string.
Note that the output is zero padded for values below 16.

Examples

assert i8(8).hex() == '08'
assert i8(10).hex() == '0a'
assert i8(15).hex() == '0f'

fn (i8) hex_full #

fn (nn i8) hex_full() string

fn (int) str #

fn (n int) str() string

str returns the value of the int as a string.

Example

assert int(-2020).str() == '-2020'

fn (int) hex #

fn (nn int) hex() string

hex returns the value of the int as a hexadecimal string.
Note that the output is not zero padded.

Examples

assert int(2).hex() == '2'
assert int(200).hex() == 'c8'

fn (int) hex2 #

fn (n int) hex2() string

hex2 returns the value of the int as a 0x-prefixed hexadecimal string.
Note that the output after 0x is not zero padded.

Examples

assert int(8).hex2() == '0x8'
assert int(15).hex2() == '0xf'
assert int(18).hex2() == '0x12'

fn (int) hex_full #

fn (nn int) hex_full() string

fn (int literal) str #

fn (n int_literal) str() string

str returns the value of the int_literal as a string.

fn (int literal) hex #

fn (nn int_literal) hex() string

hex returns the value of the int_literal as a hexadecimal string.
Note that the output is not zero padded.

fn (int literal) hex_full #

fn (nn int_literal) hex_full() string

fn (isize) str #

fn (x isize) str() string

fn (None__) free #

unsafe
fn (n &None__) free()

fn (rune) str #

fn (c rune) str() string

This was never working correctly, the issue is now fixed however the type checks in checker need to be updated. if you uncomment it you will see the issue type rune = int

fn (rune) repeat #

fn (c rune) repeat(count int) string

repeat returns a new string with count number of copies of the rune it was called on.

fn (rune) length_in_bytes #

fn (c rune) length_in_bytes() int

fn (u16) str #

fn (n u16) str() string

str returns the value of the u16 as a string.

Example

assert u16(20).str() == '20'

fn (u16) hex #

fn (nn u16) hex() string

hex returns the value of the u16 as a hexadecimal string.
Note that the output is not zero padded.

Examples

assert u16(2).hex() == '2'
assert u16(200).hex() == 'c8'

fn (u16) hex_full #

fn (nn u16) hex_full() string

fn (u32) str #

fn (nn u32) str() string

str returns the value of the u32 as a string.

Example

assert u32(20000).str() == '20000'

fn (u32) hex #

fn (nn u32) hex() string

hex returns the value of the u32 as a hexadecimal string.
Note that the output is not zero padded.

Examples

assert u32(2).hex() == '2'
assert u32(200).hex() == 'c8'

fn (u32) hex_full #

fn (nn u32) hex_full() string

fn (u64) str #

fn (nn u64) str() string

str returns the value of the u64 as a string.

Example

assert u64(2000000).str() == '2000000'

fn (u64) hex #

fn (nn u64) hex() string

hex returns the value of the u64 as a hexadecimal string.
Note that the output is not zero padded.

Examples

assert u64(2).hex() == '2'
assert u64(2000).hex() == '7d0'

fn (u64) hex_full #

fn (nn u64) hex_full() string

hex_full returns the value of the u64 as a full 16-digit hexadecimal string.

Examples

assert u64(2).hex_full() == '0000000000000002'
assert u64(255).hex_full() == '00000000000000ff'

fn (usize) str #

fn (x usize) str() string

fn (voidptr) hex_full #

fn (nn voidptr) hex_full() string

fn (voidptr) str #

fn (nn voidptr) str() string

hex returns the value of the voidptr as a hexadecimal string.
Note that the output is not zero padded.

fn (voidptr) vbytes #

unsafe
fn (data voidptr) vbytes(len int) []byte

voidptr.vbytes() - makes a V []byte structure from a C style memory buffer. NB: the data is reused, NOT copied!

enum ArrayFlags #

enum ArrayFlags {
	noslices
}

enum AttributeKind #

enum AttributeKind {
	plain
	string
	number
	comptime_define
}

enum ChanState #

enum ChanState {
	success
	not_ready
	closed
}

ChanState describes the result of an attempted channel transaction.

enum StrIntpType #

enum StrIntpType {
	si_no_str = 0
	si_c
	si_u8
	si_i8
	si_u16
	si_i16
	si_u32
	si_i32
	si_u64
	si_i64
	si_e32
	si_e64
	si_f32
	si_f64
	si_g32
	si_g64
	si_s
	si_p
	si_vp
}

============================================================================= Enum format types max 0x1F => 32 types

fn (StrIntpType) str #

fn (x StrIntpType) str() string

struct array #

struct array {
pub:
	element_size int
pub mut:
	data   voidptr
	offset int
	len    int
	cap    int
	flags  ArrayFlags
}

array is a struct, used for denoting all array types in V.
.data is a void pointer to the backing heap memory block, which avoids using generics and thus without generating extra code for every type.

fn (array) repeat #

fn (a array) repeat(count int) array

This is a dummy placeholder that will be overridden by cgen with an appropriate call to repeat_to_depth(). However the checker needs it here.

fn (array) repeat_to_depth #

unsafe
fn (a array) repeat_to_depth(count int, depth int) array

version of repeat() that handles multi dimensional arrays unsafe to call directly because depth is not checked

fn (array) sort_with_compare #

fn (mut a array) sort_with_compare(callback fn (voidptr, voidptr) int)

sort_with_compare sorts array in-place using given compare function as comparator.

fn (array) insert #

fn (mut a array) insert(i int, val voidptr)

insert inserts a value in the array at index i

fn (array) insert_many #

unsafe
fn (mut a array) insert_many(i int, val voidptr, size int)

insert_many inserts many values into the array from index i.

fn (array) prepend #

fn (mut a array) prepend(val voidptr)

prepend prepends one value to the array.

fn (array) prepend_many #

unsafe
fn (mut a array) prepend_many(val voidptr, size int)

prepend_many prepends another array to this array.

fn (array) delete #

fn (mut a array) delete(i int)

delete deletes array element at index i.

fn (array) delete_many #

fn (mut a array) delete_many(i int, size int)

delete_many deletes size elements beginning with index i

fn (array) clear #

fn (mut a array) clear()

clear clears the array without deallocating the allocated data.

fn (array) trim #

fn (mut a array) trim(index int)

trim trims the array length to "index" without modifying the allocated data. If "index" is greater than len nothing will be changed.

fn (array) first #

fn (a array) first() voidptr

first returns the first element of the array.

fn (array) last #

fn (a array) last() voidptr

last returns the last element of the array.

fn (array) pop #

fn (mut a array) pop() voidptr

pop returns the last element of the array, and removes it.

fn (array) delete_last #

fn (mut a array) delete_last()

delete_last efficiently deletes the last element of the array.

fn (array) clone #

fn (a &array) clone() array

clone returns an independent copy of a given array.
this will be overwritten by cgen with an apropriate call to .clone_to_depth() However the checker needs it here.

fn (array) clone_to_depth #

unsafe
fn (a &array) clone_to_depth(depth int) array

recursively clone given array - unsafe when called directly because depth is not checked

fn (array) push_many #

unsafe
fn (mut a3 array) push_many(val voidptr, size int)

push_many implements the functionality for pushing another array.
val is array.data and user facing usage is a << [1,2,3]

fn (array) reverse_in_place #

fn (mut a array) reverse_in_place()

reverse_in_place reverses existing array data, modifying original array.

fn (array) reverse #

fn (a array) reverse() array

reverse returns a new array with the elements of the original array in reverse order.

fn (array) free #

unsafe
fn (a &array) free()

pub fn (a []int) free() { free frees all memory occupied by the array.

fn (array) filter #

fn (a array) filter(predicate fn (voidptr) bool) array

filter creates a new array with all elements that pass the test implemented by the provided function

fn (array) any #

fn (a array) any(predicate fn (voidptr) bool) bool

any tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the array

fn (array) all #

fn (a array) all(predicate fn (voidptr) bool) bool

all tests whether all elements in the array pass the test implemented by the provided function

fn (array) map #

fn (a array) map(callback fn (voidptr) voidptr) array

map creates a new array populated with the results of calling a provided function on every element in the calling array

fn (array) sort #

fn (mut a array) sort(callback fn (voidptr, voidptr) int)

sort sorts an array in place in ascending order.

fn (array) contains #

fn (a array) contains(val voidptr) bool

contains determines whether an array includes a certain value among its entries

fn (array) index #

fn (a array) index(value voidptr) int

index returns the first index at which a given element can be found in the array or -1 if the value is not found.

fn (array) grow_cap #

fn (mut a array) grow_cap(amount int)

grow_cap grows the array's capacity by amount elements.

fn (array) grow_len #

unsafe
fn (mut a array) grow_len(amount int)

grow_len ensures that an array has a.len + amount of length

fn (array) pointers #

unsafe
fn (a array) pointers() []voidptr

pointers returns a new array, where each element is the address of the corresponding element in the array.

struct Error #

struct Error {
pub:
	msg  string
	code int
}

Error is the default implementation of IError, that is returned by e.g. error()

fn (Error) free #

unsafe
fn (e &Error) free()

struct FieldData #

struct FieldData {
pub:
	name      string
	attrs     []string
	is_pub    bool
	is_mut    bool
	is_shared bool
	typ       int
}

FieldData holds information about a field. Fields reside on structs.

struct FunctionData #

struct FunctionData {
pub:
	name        string
	attrs       []string
	args        []MethodArgs
	return_type int
	typ         int
}

FunctionData holds information about a parsed function.

struct map #

struct map {
	key_bytes int

	value_bytes int
mut:
	even_index u32

	cached_hashbits byte

	shift byte

	key_values DenseArray

	metas &u32

	extra_metas     u32
	has_string_keys bool
	hash_fn         MapHashFn
	key_eq_fn       MapEqFn
	clone_fn        MapCloneFn
	free_fn         MapFreeFn
pub mut:
	len int
}

map is the internal representation of a V map type.

fn (map) move #

fn (mut m map) move() map

fn (map) delete #

unsafe
fn (mut m map) delete(key voidptr)

Removes the mapping of a particular key from the map.

fn (map) keys #

fn (m &map) keys() array

Returns all keys in the map.

fn (map) clone #

unsafe
fn (m &map) clone() map

clone returns a clone of the map.

fn (map) free #

unsafe
fn (m &map) free()

free releases all memory resources occupied by the map.

struct MethodArgs #

struct MethodArgs {
pub:
	typ  int
	name string
}

MethodArgs holds type information for function and/or method arguments.

struct SortedMap #

struct SortedMap {
	value_bytes int
mut:
	root &mapnode
pub mut:
	len int
}

fn (SortedMap) delete #

fn (mut m SortedMap) delete(key string)

fn (SortedMap) keys #

fn (m &SortedMap) keys() []string

fn (SortedMap) free #

fn (mut m SortedMap) free()

fn (SortedMap) print #

fn (m SortedMap) print()

struct string #

struct string {
pub:
	str &byte = 0
	len int
mut:
	is_lit int
}

fn (string) after #

fn (s string) after(sub string) string

TODO: deprecate either .all_after_last or .after

Examples

assert '23:34:45.234'.after(':') == '45.234'
assert 'abcd'.after('z') == 'abcd'

fn (string) after_char #

fn (s string) after_char(sub byte) string

after_char returns the contents after the first occurence of sub character in the string.
If the substring is not found, it returns the full input string.

Examples

assert '23:34:45.234'.after_char(`:`) == '34:45.234'
assert 'abcd'.after_char(`:`) == 'abcd'

fn (string) all_after #

fn (s string) all_after(sub string) string

all_after returns the contents after sub in the string.
If the substring is not found, it returns the full input string.

Examples

assert '23:34:45.234'.all_after('.') == '234'
assert 'abcd'.all_after('z') == 'abcd'

fn (string) all_after_last #

fn (s string) all_after_last(sub string) string

all_after_last returns the contents after the last occurence of sub in the string.
If the substring is not found, it returns the full input string.

Examples

assert '23:34:45.234'.all_after_last(':') == '45.234'
assert 'abcd'.all_after_last('z') == 'abcd'

fn (string) all_before #

fn (s string) all_before(sub string) string

all_before returns the contents before sub in the string.
If the substring is not found, it returns the full input string.

Examples

assert '23:34:45.234'.all_before('.') == '23:34:45'
assert 'abcd'.all_before('.') == 'abcd'

fn (string) all_before_last #

fn (s string) all_before_last(sub string) string

all_before_last returns the contents before the last occurence of sub in the string.
If the substring is not found, it returns the full input string.

Examples

assert '23:34:45.234'.all_before_last(':') == '23:34'
assert 'abcd'.all_before_last('.') == 'abcd'

fn (string) before #

fn (s string) before(sub string) string

TODO: deprecate and remove either .before or .all_before

Examples

assert '23:34:45.234'.before('.') == '23:34:45'
assert 'abcd'.before('.') == 'abcd'

fn (string) bool #

fn (s string) bool() bool

bool returns true if the string equals the word "true" it will return false otherwise.

fn (string) byte #

fn (s string) byte() u8

u8 returns the value of the string as u8 '1'.u8() == u8(1).

fn (string) bytes #

fn (s string) bytes() []byte

bytes returns the string converted to a byte array.

fn (string) capitalize #

fn (s string) capitalize() string

capitalize returns the string with the first character capitalized.

Example

assert 'hello'.capitalize() == 'Hello'

fn (string) clone #

fn (a string) clone() string

clone returns a copy of the V string a.

fn (string) compare #

fn (s string) compare(a string) int

compare returns -1 if s < a, 0 if s == a, and 1 if s > a

fn (string) contains #

fn (s string) contains(substr string) bool

contains returns true if the string contains substr.

fn (string) contains_any #

fn (s string) contains_any(chars string) bool

contains_any returns true if the string contains any chars in chars.

fn (string) contains_any_substr #

fn (s string) contains_any_substr(substrs []string) bool

contains_any_substr returns true if the string contains any of the strings in substrs.

fn (string) count #

fn (s string) count(substr string) int

count returns the number of occurrences of substr in the string.
count returns -1 if no substr could be found.

fn (string) ends_with #

fn (s string) ends_with(p string) bool

ends_with returns true if the string ends with p.

fn (string) f32 #

fn (s string) f32() f32

f32 returns the value of the string as f32 '1.0'.f32() == f32(1).

fn (string) f64 #

fn (s string) f64() f64

f64 returns the value of the string as f64 '1.0'.f64() == f64(1).

fn (string) fields #

fn (s string) fields() []string

fields returns a string array of the string split by \t and

Examples

assert '\t\tv = v'.fields() == ['v', '=', 'v']
assert '  sss   ssss'.fields() == ['sss', 'ssss']

fn (string) find_between #

fn (s string) find_between(start string, end string) string

find_between returns the string found between start string and end string.

Example

assert 'hey [man] how you doin'.find_between('[', ']') == 'man'

fn (string) free #

unsafe
fn (s &string) free()

free allows for manually freeing the memory occupied by the string

fn (string) hash #

fn (s string) hash() int

hash returns an integer hash of the string.

fn (string) i16 #

fn (s string) i16() i16

i16 returns the value of the string as i16 '1'.i16() == i16(1).

fn (string) i64 #

fn (s string) i64() i64

i64 returns the value of the string as i64 '1'.i64() == i64(1).

fn (string) i8 #

fn (s string) i8() i8

i8 returns the value of the string as i8 '1'.i8() == i8(1).

fn (string) index #

fn (s string) index(p string) ?int

index returns the position of the first character of the input string.
It will return none if the input string can't be found.

fn (string) index_after #

fn (s string) index_after(p string, start int) int

index_after returns the position of the input string, starting search from start position.

fn (string) index_any #

fn (s string) index_any(chars string) int

index_any returns the position of any of the characters in the input string - if found.

fn (string) index_byte #

fn (s string) index_byte(c byte) int

index_byte returns the index of byte c if found in the string.
index_byte returns -1 if the byte can not be found.

fn (string) int #

fn (s string) int() int

int returns the value of the string as an integer '1'.int() == 1.

fn (string) is_capital #

fn (s string) is_capital() bool

is_capital returns true, if the first character in the string s, is a capital letter, and the rest are NOT.

Examples

assert 'Hello'.is_capital() == true
assert 'HelloWorld'.is_capital() == false

fn (string) is_lower #

fn (s string) is_lower() bool

is_lower returns true if all characters in the string is lowercase.

Example

assert 'hello developer'.is_lower() == true

fn (string) is_title #

fn (s string) is_title() bool

is_title returns true if all words of the string are capitalized.

Example

assert 'Hello V Developer'.is_title() == true

fn (string) is_upper #

fn (s string) is_upper() bool

is_upper returns true if all characters in the string is uppercase.

Example

assert 'HELLO V'.is_upper() == true

fn (string) last_index #

fn (s string) last_index(p string) ?int

last_index returns the position of the last occurence of the input string.

fn (string) last_index_byte #

fn (s string) last_index_byte(c byte) int

last_index_byte returns the index of the last occurence of byte c if found in the string.
last_index_byte returns -1 if the byte is not found.

fn (string) limit #

fn (s string) limit(max int) string

limit returns a portion of the string, starting at 0 and extending for a given number of characters afterward.
'hello'.limit(2) => 'he' 'hi'.limit(10) => 'hi'

fn (string) repeat #

fn (s string) repeat(count int) string

repeat returns a new string with count number of copies of the string it was called on.

fn (string) replace #

fn (s string) replace(rep string, with string) string

replace replaces all occurences of rep with the string passed in with.

fn (string) replace_each #

fn (s string) replace_each(vals []string) string

replace_each replaces all occurences of the string pairs given in vals.

Example

assert 'ABCD'.replace_each(['B','C/','C','D','D','C']) == 'AC/DC'

fn (string) replace_once #

fn (s string) replace_once(rep string, with string) string

replace_once replaces the first occurence of rep with the string passed in with.

fn (string) reverse #

fn (s string) reverse() string

reverse returns a reversed string.

Example

assert 'Hello V'.reverse() == 'V olleH'

fn (string) runes #

fn (s string) runes() []rune

runes returns an array of all the utf runes in the string s which is useful if you want random access to them

fn (string) split #

fn (s string) split(delim string) []string

If delim is empty the string is split by it's characters.

Examples

assert 'A B C'.split(' ') == ['A','B','C']
assert 'DEF'.split('') == ['D','E','F']

fn (string) split_any #

fn (s string) split_any(delim string) []string

Split a string using the chars in the delimiter string as delimiters chars.
If the delimiter string is empty then .split() is used.

Example

"first row\nsecond row".split_any(" \n") == ['first', 'row', 'second', 'row']

fn (string) split_into_lines #

fn (s string) split_into_lines() []string

split_into_lines splits the string by newline characters.
newlines are stripped.
Both \n and \r\n newline endings are supported.

fn (string) split_nth #

fn (s string) split_nth(delim string, nth int) []string

split_nth splits the string based on the passed delim substring.
It returns the first Nth parts. When N=0, return all the splits.
The last returned element has the remainder of the string, even if the remainder contains more delim substrings.

fn (string) starts_with #

fn (s string) starts_with(p string) bool

starts_with returns true if the string starts with p.

fn (string) starts_with_capital #

fn (s string) starts_with_capital() bool

starts_with_capital returns true, if the first character in the string s, is a capital letter, even if the rest are not.

Examples

assert 'Hello'.starts_with_capital() == true
assert 'Hello. World.'.starts_with_capital() == true

fn (string) str #

fn (s string) str() string

str returns a copy of the string

fn (string) strip_margin #

fn (s string) strip_margin() string

strip_margin allows multi-line strings to be formatted in a way that removes white-space before a delimeter. by default | is used.
Note: the delimiter has to be a byte at this time. That means surrounding the value in ``.

Example: st := 'Hello there, |this is a string, | Everything before the first | is removed'.strip_margin() Returns: Hello there, this is a string, Everything before the first | is removed

fn (string) strip_margin_custom #

fn (s string) strip_margin_custom(del byte) string

strip_margin_custom does the same as strip_margin but will use del as delimiter instead of |

fn (string) substr #

fn (s string) substr(start int, end int) string

substr returns the string between index positions start and end.

Example

assert 'ABCD'.substr(1,3) == 'BC'

fn (string) title #

fn (s string) title() string

title returns the string with each word capitalized.

Example

assert 'hello v developer'.title() == 'Hello V Developer'

fn (string) to_lower #

fn (s string) to_lower() string

to_lower returns the string in all lowercase characters.
TODO only works with ASCII

fn (string) to_upper #

fn (s string) to_upper() string

to_upper returns the string in all uppercase characters.

Example

assert 'Hello V'.to_upper() == 'HELLO V'

fn (string) to_wide #

fn (_str string) to_wide() &u16

fn (string) trim #

fn (s string) trim(cutset string) string

trim strips any of the characters given in cutset from the start and end of the string.

Example

assert ' ffHello V ffff'.trim(' f') == 'Hello V'

fn (string) trim_left #

fn (s string) trim_left(cutset string) string

trim_left strips any of the characters given in cutset from the left of the string.

Example

assert 'd Hello V developer'.trim_left(' d') == 'Hello V developer'

fn (string) trim_prefix #

fn (s string) trim_prefix(str string) string

trim_prefix strips str from the start of the string.

Example

assert 'WorldHello V'.trim_prefix('World') == 'Hello V'

fn (string) trim_right #

fn (s string) trim_right(cutset string) string

trim_right strips any of the characters given in cutset from the right of the string.

Example

assert ' Hello V d'.trim_right(' d') == ' Hello V'

fn (string) trim_space #

fn (s string) trim_space() string

trim_space strips any of , \n, \t, \v, \f, \r from the start and end of the string.

Example

assert ' Hello V '.trim_space() == 'Hello V'

fn (string) trim_suffix #

fn (s string) trim_suffix(str string) string

trim_suffix strips str from the end of the string.

Example

assert 'Hello VWorld'.trim_suffix('World') == 'Hello V'

fn (string) u16 #

fn (s string) u16() u16

u16 returns the value of the string as u16 '1'.u16() == u16(1).

fn (string) u32 #

fn (s string) u32() u32

u32 returns the value of the string as u32 '1'.u32() == u32(1).

fn (string) u64 #

fn (s string) u64() u64

u64 returns the value of the string as u64 '1'.u64() == u64(1).

fn (string) utf32_code #

fn (_rune string) utf32_code() int

Convert utf8 to utf32

struct StrIntpCgenData #

struct StrIntpCgenData {
pub:
	str string
	fmt string
	d   string
}

storing struct used by cgen

struct StrIntpData #

struct StrIntpData {
pub:
	str string

	fmt u32
	d   StrIntpMem
}

NOTE: LOW LEVEL struct storing struct passed to V in the C code

struct StrIntpMem #

union StrIntpMem {
pub mut:
	d_c   u32
	d_u8  byte
	d_i8  i8
	d_u16 u16
	d_i16 i16
	d_u32 u32
	d_i32 int
	d_u64 u64
	d_i64 i64
	d_f32 f32
	d_f64 f64
	d_s   string
	d_p   voidptr
	d_vp  voidptr
}

============================================================================= Union data

struct StructAttribute #

struct StructAttribute {
pub:
	name    string
	has_arg bool
	arg     string
	kind    AttributeKind
}

struct VAssertMetaInfo #

struct VAssertMetaInfo {
pub:
	fpath   string
	line_nr int
	fn_name string
	src     string
	op      string
	llabel  string
	rlabel  string
	lvalue  string
	rvalue  string
}

VAssertMetaInfo is used during assertions. An instance of it is filled in by compile time generated code, when an assertion fails.

fn (VAssertMetaInfo) free #

unsafe
fn (ami &VAssertMetaInfo) free()

free is used to free the memory occupied by the assertion meta data.
It is called by cb_assertion_failed, and cb_assertion_ok in the preludes, once they are done with reporting/formatting the meta data.