builtin #

fn compare_f32 #

fn compare_f32(a &f32, b &f32) int

compare_f32 for []f32 sort_with_compare() ref. compare_i64(...)

fn compare_f64 #

fn compare_f64(a &f64, b &f64) int

compare_f64 for []f64 sort_with_compare() ref. compare_i64(...)

fn compare_i64 #

fn compare_i64(a &i64, b &i64) int

compare_i64 for []i64 sort_with_compare() sort []i64 with quicksort usage : mut x := [i64(100),10,70,28,92] x.sort_with_compare(compare_i64) println(x) // Sorted i64 Array output: [10, 28, 70, 92, 100]

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 #

fn cstring_to_vstring(cstr byteptr) string

cstring_to_vstring creates a copy of cstr and turns it into a v string.

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) Option

error returns an optional containing the error given in message. if ouch { return error('an error occurred') }

fn error2 #

fn error2(message string) Option2

error returns an optional containing the error given in message. if ouch { return error('an error occurred') }

fn error_with_code #

fn error_with_code(message string, code int) Option

error_with_code returns an optional containing both error message and error code. if ouch { return error_with_code('an error occurred',1) }

fn error_with_code2 #

fn error_with_code2(message string, code int) Option2

error_with_code returns an optional containing both error message and error code. if ouch { return error_with_code('an error occurred',1) }

fn exit #

fn exit(code int)

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 #

fn free(ptr voidptr)

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

fn is_atty #

fn is_atty(fd int) int

is_atty returns 1 if the fd file descriptor is open and refers to a terminal

fn isnil #

fn isnil(v voidptr) bool

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

fn malloc #

fn malloc(n int) byteptr

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 memdup #

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 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 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 string_from_wide #

fn string_from_wide(_wstr &u16) string

fn string_from_wide2 #

fn string_from_wide2(_wstr &u16, len int) string

fn tos #

fn tos(s byteptr, len int) string

tos converts a C string to a V string. String data is reused, not copied.

fn tos2 #

fn tos2(s byteptr) string

tos2 does the same as tos, but also calculates the length. Called by string(bytes) casts. Used only internally.

fn tos3 #

fn tos3(s charptr) string

tos3 does the same as tos2, but for char*, to avoid warnings.

fn tos4 #

fn tos4(s byteptr) string

tos4 does the same as tos2, but returns an empty string on nil ptr.

fn tos5 #

fn tos5(s charptr) string

tos5 does the same as tos4, but for char*, to avoid warnings.

fn tos_clone #

fn tos_clone(s byteptr) string

tos_clone returns a copy of s.

fn tos_lit #

fn tos_lit(s charptr) string

fn utf32_to_str #

fn utf32_to_str(code u32) string

Convert utf32 to utf8 utf32 == Codepoint

fn utf32_to_str_no_malloc #

fn utf32_to_str_no_malloc(code u32, buf voidptr) 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_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_calloc #

fn v_calloc(n int) byteptr

v_calloc dynamically allocates a zeroed n bytes block of memory on the heap. v_calloc returns a byteptr pointing to the memory address of the allocated space.

fn v_realloc #

fn v_realloc(b byteptr, n int) byteptr

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.

fn vcalloc #

fn vcalloc(n int) byteptr

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 vstrlen #

fn vstrlen(s byteptr) int

vstrlen returns the V length of the C string s (0 terminator is not counted).

fn ([]byte) bytestr #

fn (b []byte) bytestr() string

TODO remove this once runes are implemented

fn ([]byte) clone #

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

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) sort #

fn (mut a []int) sort()

sort sorts an array of int in place in ascending order.

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 ([]string) eq #

fn (a1 []string) eq(a2 []string) bool

array_eq<T> checks if two arrays contain all the same elements in the same order. []int == []int (also for: i64, f32, f64, byte, string) eq checks if the arrays have the same elements or not. TODO: make it work with all types.

fn ([]string) index #

fn (a []string) index(v string) 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 ([]string) join #

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

fn (s []string) substr(a, b int) string { return join_strings(s.slice_fast(a, b)) } join joins a string array into a string using del delimiter.

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 #

fn (mut s []string) sort()

sort sorts the string array.

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) 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

Define this on byte as well, so that we can do s[0].is_capital()

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: , \n, \t, \v, \f, \r, 0x85, 0xa0

Example

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

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 (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.

fn (byteptr) vbytes #

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 #

fn (bp byteptr) vstring() string

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

fn (byteptr) vstring_with_len #

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 &lt;- a succeeded. Both the test and push transaction is done atomically.

fn (charptr) vstring #

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 #

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 (f32) str #

fn (x f32) str() string

str returns a f32 as string in suitable notation.

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) 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 (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 (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 (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 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 (Option) str #

fn (o Option) str() string

str returns the string representation of the Option.

fn (Option2) str #

fn (o Option2) str() string

/*

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 (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 (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 (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 (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 #

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!

struct array #

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

array is a struct used for denoting array types in V

fn (array) repeat #

fn (a array) repeat(count int) array

repeat returns a new array with the given array elements repeated given times.

fn (array) sort_with_compare #

fn (mut a array) sort_with_compare(compare voidptr)

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 #

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 #

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) 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.

fn (array) push_many #

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 &lt;&lt; [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 #

fn (a &array) free()

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

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 #

fn (mut a array) grow_len(amount int)

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

fn (array) pointers #

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 holds information about an error instance

struct FieldData #

struct FieldData {
pub:
	name   string
	attrs  []string
	is_pub bool
	is_mut 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 #

fn (mut m map) delete(key string)

delete this

fn (map) delete_1 #

fn (mut m map) delete_1(key voidptr)

Removes the mapping of a particular key from the map.

fn (map) keys #

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

bootstrap delete this

fn (map) clone #

fn (m &map) clone() map

clone returns a clone of the map.

fn (map) free #

fn (m &map) free()

free releases all memory resources occupied by the map.

struct MethodArgs #

struct MethodArgs {
pub:
	typ int
}

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 byteptr
	len int
mut:
	is_lit int
}

fn (string) after #

fn (s string) after(dot string) string

after returns the contents after the last occurence of dot in the string.

Example

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

fn (string) after_char #

fn (s string) after_char(dot byte) string

after_char returns the contents after the first occurence of dot character in the string.

Example

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

fn (string) all_after #

fn (s string) all_after(dot string) string

all_after returns the contents after dot in the string.

Example

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

fn (string) all_after_last #

fn (s string) all_after_last(dot string) string

all_after_last returns the contents after the last occurence of dot in the string.

Example

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

fn (string) all_before #

fn (s string) all_before(dot string) string

all_before returns the contents before dot in the string.

Example

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

fn (string) all_before_last #

fn (s string) all_before_last(dot string) string

all_before_last returns the contents before the last occurence of dot in the string.

Example

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

fn (string) before #

fn (s string) before(dot string) string

before returns the contents before dot in the string.

Example

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

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) 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) 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

Example

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

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 #

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 is a capital letter.

Example

assert 'Hello'.is_capital() == true

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 is 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

TODO 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) split #

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

split splits the string to an array by delim. 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_by_whitespace #

fn (s string) split_by_whitespace() []string

split_by_whitespace - extract only the non whitespace tokens/words from the given string s. example: ' sss ssss'.split_by_whitespace() => ['sss', 'ssss']

fn (string) split_into_lines #

fn (s string) split_into_lines() []string

split_into_lines splits the string by newline characters. Both \n and \r\n newline endings is 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) str #

fn (s string) str() string

str returns the string itself.

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) ustring #

fn (s string) ustring() ustring

ustring converts the string to a unicode string.

fn (string) ustring_tmp #

fn (s string) ustring_tmp() ustring

fn (string) utf32_code #

fn (_rune string) utf32_code() int

Convert utf8 to utf32

struct ustring #

struct ustring {
pub mut:
	s     string
	runes []int
	len   int
}

mut: hash_cache int NB string.is_lit is an enumeration of the following: .is_lit == 0 => a fresh string, should be freed by autofree .is_lit == 1 => a literal string from .rodata, should NOT be freed .is_lit == -98761234 => already freed string, protects against double frees. ---------> ^^^^^^^^^ calling free on these is a bug. Any other value means that the string has been corrupted.

fn (ustring) str #

fn (s ustring) str() string

str returns the string itself.

fn (ustring) add #

fn (u ustring) add(a ustring) ustring

add concatenates ustring with the string given in s.

fn (ustring) index_after #

fn (u ustring) index_after(p ustring, start int) int

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

fn (ustring) count #

fn (u ustring) count(substr ustring) int

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

fn (ustring) substr #

fn (u ustring) substr(_start int, _end int) string

substr returns the string between index positions _start and _end.

Example

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

fn (ustring) left #

fn (u ustring) left(pos int) string

left returns the nth leftmost characters of the ustring.

Example

assert 'hello'.left(2) == 'he'

fn (ustring) right #

fn (u ustring) right(pos int) string

right returns the nth rightmost characters of the ustring.

Example

assert 'hello'.right(2) == 'lo'

fn (ustring) at #

fn (u ustring) at(idx int) string

at returns the string at index idx.

Example

assert 'ABC'.at(1) == 'B'

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.