const (
si_s_code = '0xfe10'
si_g32_code = '0xfe0e'
si_g64_code = '0xfe0f'
)
==================================================================================== Utility for the compiler "auto_str_methods.v" ==================================================================================== substitute old _STR calls
fn compare_strings(a &string, b &string) int
compare_strings returns -1 if a < b, 1 if a > b else 0.
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(cstr &char) string
cstring_to_vstring creates a copy of cstr and turns it into a v string.
fn eprint(s string)
eprint prints a message to stderr. Both stderr and stdout are flushed.
fn eprintln(s string)
eprintln prints a message with a line end, to stderr. Both stderr and stdout are flushed.
fn error(message string) IError
error returns a default error instance containing the error given in message.
`if ouch { return error('an error occurred') }`
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(code int)
exit terminates execution immediately and returns exit code to the shell.
fn f32_abs(a f32) f32
f32_abs returns the absolute value of a as a f32 value.
assert f32_abs(-2.0) == 2.0
fn f32_max(a f32, b f32) f32
f32_max returns the largest f32 of input a and b.
assert f32_max(2.0,3.0) == 3.0
fn f32_min(a f32, b f32) f32
f32_min returns the smallest f32 of input a and b.
assert f32_min(2.0,3.0) == 2.0
fn f64_max(a f64, b f64) f64
f64_max returns the largest f64 of input a and b.
assert f64_max(2.0,3.0) == 3.0
fn free(ptr voidptr)
free allows for manually freeing memory allocated at the address ptr.
fn gc_check_leaks()
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 u8, in_base int, in_upper_case bool) u32
convert from data format to compact u32
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 u8, in_base int, in_upper_case bool) u64
========================================= u32/u64 bit compact format ___ 32 24 16 8 ___ | | | | _3333333333222222222211111111110000000000 _9876543210987654321098765432109876543210 _nPPPPPPPPBBBBWWWWWWWWWWTDDDDDDDSUAA===== = data type 5 bit max 32 data type A allign 2 bit Note: for now only 1 used! U uppercase 1 bit 0 do nothing, 1 do to_upper() S sign 1 bit show the sign if positive D decimals 7 bit number of decimals digit to show T tail zeros 1 bit 1 remove tail zeros, 0 do nothing W Width 10 bit number of char for padding and indentation B num base 4 bit start from 2, 0 for base 10 P pad char 1/8 bit padding char (in u32 format reduced to 1 bit as flag for 0 padding) -------------- TOTAL: 39/32 bit ========================================= convert from data format to compact u64
fn is_atty(fd int) int
fn isnil(v voidptr) bool
isnil returns true if an object is nil (only for C objects).
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(n int) &byte
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(src voidptr, sz int) voidptr
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_optional_not_set(s string)
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 print_backtrace()
print_backtrace shows a backtrace of the current call stack on stdout
fn println(s string)
println prints a message with a line end, to stdout. stdout is flushed.
fn proc_pidpath(int, voidptr, int) int
fn ptr_str(ptr voidptr) string
----- value to string functions ----- ptr_str returns the address of ptr as a string.
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(data_len int, in_data voidptr) string
interpolation function
fn str_intp_g32(in_str string) string
fn str_intp_g64(in_str string) string
fn str_intp_rune(in_str string) string
fn str_intp_sq(in_str string) string
fn str_intp_sub(base_str string, in_str string) string
replace %% with the in_str
fn string_from_wide(_wstr &u16) string
fn string_from_wide2(_wstr &u16, len int) string
fn tos(s &byte, len int) string
tos converts a C string to a V string. String data is reused, not copied.
fn tos2(s &byte) string
tos2 does the same as tos, but also calculates the length. Called by string(bytes) casts. Used only internally.
fn tos3(s &char) string
tos3 does the same as tos2, but for char*, to avoid warnings.
fn tos4(s &byte) string
tos4 does the same as tos2, but returns an empty string on nil ptr.
fn tos5(s &char) string
tos5 does the same as tos4, but for char*, to avoid warnings.
fn tos_clone(s &byte) string
tos_clone returns a copy of s.
fn tos_lit(s &char) string
fn utf32_to_str(code u32) string
Convert utf32 to utf8 utf32 == Codepoint
fn utf32_to_str_no_malloc(code u32, buf voidptr) string
fn utf8_char_len(b byte) int
fn utf8_getchar() int
Reads an utf8 character from standard input
fn utf8_str_len(s string) int
Calculate string length for in number of codepoints
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(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(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(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 vstrlen(s &byte) int
vstrlen returns the V length of the C string s (0 terminator is not counted).
interface IError {
msg string
code int
}
IError holds information about an error instance
fn (err IError) str() string
fn (ie &IError) free()
fn (b []byte) bytestr() string
TODO: remove this once runes are implemented
fn (b []byte) clone() []byte
fn (b []byte) hex() string
hex returns a string with the hexadecimal representation of the byte elements of the array.
fn (mut a []int) sort()
sort sorts an array of int in place in ascending order.
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 (ra []rune) string() string
string converts a rune array to a string
fn (a1 []string) eq(a2 []string) bool
eq checks if the arrays have the same elements or not. TODO: make it work with all types.
fn (mut a []string) free()
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 (a []string) join(sep string) string
join joins a string array into a string using sep separator.
assert ['Hello','V'].join(' ') == 'Hello V'
fn (s []string) join_lines() string
join joins a string array into a string using a \n newline delimiter.
fn (mut s []string) sort()
sort sorts the string array.
fn (mut s []string) sort_by_len()
sort_by_len sorts the the string array by each string's .len length.
fn (mut s []string) sort_ignore_case()
sort_ignore_case sorts the string array using case insesitive comparing.
fn (a []string) str() string
str returns a string representation of the array of strings => '["a", "b", "c"]'.
fn (b bool) str() string
str returns the value of the bool as a string.
assert (2 > 1).str() == 'true'
fn (b byte) ascii_str() string
ascii_str returns the contents of byte as a zero terminated ASCII string character.
assert byte(97).ascii_str() == 'a'
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.
assert byte(2).hex() == '02'
assert byte(15).hex() == '0f'
assert byte(255).hex() == 'ff'
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.
assert byte(`0`) == true
fn (c byte) is_capital() bool
Define this on byte as well, so that we can do s[0].is_capital()
fn (c byte) is_digit() bool
is_digit returns true if the byte is in range 0-9 and false otherwise.
assert byte(`9`) == true
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.
assert byte(`F`) == true
fn (c byte) is_letter() bool
is_letter returns true if the byte is in range a-z or A-Z and false otherwise.
assert byte(`V`) == true
fn (c byte) is_oct_digit() bool
is_oct_digit returns true if the byte is in range 0-7 and false otherwise.
assert byte(`7`) == true
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
assert byte(` `).is_space() == true
fn (nn &byte) 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 (b byte) str() string
str returns the contents of byte as a zero terminated string.
assert byte(111).str() == '111'
fn (b byte) str_escaped() string
str_escaped returns the contents of byte as an escaped string.
assert byte(0).str_escaped() == r'`\0`'
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 (data &byte) vbytes(len int) []byte
NB: this file will be removed soon byteptr.vbytes() - makes a V []byte structure from a C style memory buffer. NB: the data is reused, NOT copied!
fn (bp &byte) 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 (bp &byte) 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 (bp &byte) 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 (bp &byte) 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 (bp &byte) 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 (bp &byte) 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 (bp &byte) 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 (bp &byte) 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 (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 (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 (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 (cptr &char) str() string
fn (cp &char) vstring() string
vstring converts C char* to V string. NB: the string data is reused, NOT copied.
fn (cp &char) vstring() string
vstring converts C char* to V string. NB: the string data is reused, NOT copied.
fn (cp &char) 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 (cp &char) 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 (cp &char) 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 (cp &char) 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 (cp &char) vstring_with_len(len int) string
vstring_with_len converts C char* to V string. NB: the string data is reused, NOT copied.
fn (cp &char) vstring_with_len(len int) string
vstring_with_len converts C char* to V string. NB: the string data is reused, NOT copied.
fn (x f32) str() string
str returns a f32 as string in suitable notation.
fn (x f32) strg() string
strg return a f32 as string in "g" printf format
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.
assert f32(1.234).strsci(3) == '1.234e+00'
fn (x f32) strlong() string
strlong returns a decimal notation of the f32 as a string.
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).
assert f32(2.0).eq_epsilon(2.0)
fn (x f64) str() string
str return a f64 as string in suitable notation.
fn (x f64) strg() string
strg return a f64 as string in "g" printf format
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.
assert f64(1.234).strsci(3) == '1.234e+00'
fn (x f64) strlong() string
strlong returns a decimal notation of the f64 as a string.
assert f64(1.23456).strlong() == '1.23456'
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).
assert f64(2.0).eq_epsilon(2.0)
fn (d float_literal) str() string
str returns the value of the float_literal as a string.
fn (n i16) str() string
str returns the value of the i16 as a string.
assert i16(-20).str() == '-20'
fn (nn i16) hex() string
hex returns the value of the i16 as a hexadecimal string. Note that the output is not zero padded.
assert i16(2).hex() == '2'
assert i16(200).hex() == 'c8'
fn (nn i64) str() string
str returns the value of the i64 as a string.
assert i64(-200000).str() == '-200000'
fn (nn i64) hex() string
hex returns the value of the i64 as a hexadecimal string. Note that the output is not zero padded.
assert i64(2).hex() == '2'
assert i64(-200).hex() == 'ffffffffffffff38'
assert i64(2021).hex() == '7e5'
fn (n i8) str() string
str returns the value of the i8 as a string.
assert i8(-2).str() == '-2'
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.
assert i8(8).hex() == '08'
assert i8(10).hex() == '0a'
assert i8(15).hex() == '0f'
fn (n int) str() string
str returns the value of the int as a string.
assert int(-2020).str() == '-2020'
fn (nn int) hex() string
hex returns the value of the int as a hexadecimal string. Note that the output is not zero padded.
assert int(2).hex() == '2'
assert int(200).hex() == 'c8'
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.
assert int(8).hex2() == '0x8'
assert int(15).hex2() == '0xf'
assert int(18).hex2() == '0x12'
fn (n int_literal) str() string
str returns the value of the int_literal as a string.
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 (n &None__) free()
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 (x size_t) str() string
fn (n u16) str() string
str returns the value of the u16 as a string.
assert u16(20).str() == '20'
fn (nn u16) hex() string
hex returns the value of the u16 as a hexadecimal string. Note that the output is not zero padded.
assert u16(2).hex() == '2'
assert u16(200).hex() == 'c8'
fn (nn u32) str() string
str returns the value of the u32 as a string.
assert u32(20000).str() == '20000'
fn (nn u32) hex() string
hex returns the value of the u32 as a hexadecimal string. Note that the output is not zero padded.
assert u32(2).hex() == '2'
assert u32(200).hex() == 'c8'
fn (nn u64) str() string
str returns the value of the u64 as a string.
assert u64(2000000).str() == '2000000'
fn (nn u64) hex() string
hex returns the value of the u64 as a hexadecimal string. Note that the output is not zero padded.
assert u64(2).hex() == '2'
assert u64(2000).hex() == '7d0'
fn (nn u64) hex_full() string
hex_full returns the value of the u64 as a full 16-digit hexadecimal string.
assert u64(2).hex_full() == '0000000000000002'
assert u64(255).hex_full() == '00000000000000ff'
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 (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 AttributeKind {
plain
string
number
comptime_define
}
enum ChanState {
success
not_ready
closed
}
ChanState describes the result of an attempted channel transaction.
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 (x StrIntpType) str() string
struct array {
pub:
element_size int
pub mut:
data voidptr
offset int
len int
cap int
}
array is a struct used for denoting array types in V
fn (a array) repeat(count int) array
repeat returns a new array with the given array elements repeated given times. cgen will replace this with an apropriate call to repeat_to_depth() 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 (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 (mut a array) sort_with_compare(compare voidptr)
sort_with_compare sorts array in-place using given compare function as comparator.
fn (mut a array) insert(i int, val voidptr)
insert inserts a value in the array at index i
fn (mut a array) insert_many(i int, val voidptr, size int)
insert_many inserts many values into the array from index i.
fn (mut a array) prepend(val voidptr)
prepend prepends one value to the array.
fn (mut a array) prepend_many(val voidptr, size int)
prepend_many prepends another array to this array.
fn (mut a array) delete(i int)
delete deletes array element at index i.
fn (mut a array) delete_many(i int, size int)
delete_many deletes size elements beginning with index i
fn (mut a array) clear()
clear clears the array without deallocating the allocated data.
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 (a array) first() voidptr
first returns the first element of the array.
fn (a array) last() voidptr
last returns the last element of the array.
fn (mut a array) pop() voidptr
pop returns the last element of the array, and removes it.
fn (mut a array) delete_last()
delete_last efficiently deletes the last element of the array.
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 (a &array) clone_to_depth(depth int) array
recursively clone given array - unsafe when called directly because depth is not checked
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 (mut a array) reverse_in_place()
reverse_in_place reverses existing array data, modifying original array.
fn (a array) reverse() array
reverse returns a new array with the elements of the original array in reverse order.
fn (a &array) free()
pub fn (a []int) free() { free frees all memory occupied by the array.
fn (mut a array) grow_cap(amount int)
grow_cap grows the array's capacity by amount elements.
fn (mut a array) grow_len(amount int)
grow_len ensures that an array has a.len + amount of length
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 {
pub:
msg string
code int
}
Error is the default implementation of IError, that is returned by e.g. error()
fn (e &Error) free()
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 {
pub:
name string
attrs []string
args []MethodArgs
return_type int
typ int
}
FunctionData holds information about a parsed function.
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 (mut m map) move() map
fn (mut m map) delete(key voidptr)
Removes the mapping of a particular key from the map.
fn (m &map) clone() map
clone returns a clone of the map.
fn (m &map) free()
free releases all memory resources occupied by the map.
struct MethodArgs {
pub:
typ int
name string
}
MethodArgs holds type information for function and/or method arguments.
struct SortedMap {
value_bytes int
mut:
root &mapnode
pub mut:
len int
}
fn (mut m SortedMap) delete(key string)
fn (m &SortedMap) keys() []string
fn (mut m SortedMap) free()
fn (m SortedMap) print()
struct string {
pub:
str &byte = 0
len int
mut:
is_lit int
}
fn (s string) after(sub string) string
after returns the contents after the last occurence of sub in the string. If the substring is not found, it returns the full input string. TODO: deprecate either .all_after_last or .after
assert '23:34:45.234'.after(':') == '45.234'
assert 'abcd'.after('z') == 'abcd'
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.
assert '23:34:45.234'.after_char(`:`) == '34:45.234'
assert 'abcd'.after_char(`:`) == 'abcd'
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.
assert '23:34:45.234'.all_after('.') == '234'
assert 'abcd'.all_after('z') == 'abcd'
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.
assert '23:34:45.234'.all_after_last(':') == '45.234'
assert 'abcd'.all_after_last('z') == 'abcd'
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.
assert '23:34:45.234'.all_before('.') == '23:34:45'
assert 'abcd'.all_before('.') == 'abcd'
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.
assert '23:34:45.234'.all_before_last(':') == '23:34'
assert 'abcd'.all_before_last('.') == 'abcd'
fn (s string) before(sub string) string
before returns the contents before sub in the string. If the substring is not found, it returns the full input string. TODO: deprecate and remove either .before or .all_before
assert '23:34:45.234'.before('.') == '23:34:45'
assert 'abcd'.before('.') == 'abcd'
fn (s string) bool() bool
bool returns true if the string equals the word "true" it will return false otherwise.
fn (s string) bytes() []byte
bytes returns the string converted to a byte array.
fn (s string) capitalize() string
capitalize returns the string with the first character capitalized.
assert 'hello'.capitalize() == 'Hello'
fn (a string) clone() string
clone returns a copy of the V string a.
fn (s string) contains(substr string) bool
contains returns true if the string contains substr.
fn (s string) contains_any(chars string) bool
contains_any returns true if the string contains any chars in chars.
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 (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 (s string) ends_with(p string) bool
ends_with returns true if the string ends with p.
fn (s string) f32() f32
f32 returns the value of the string as f32 '1.0'.f32() == f32(1).
fn (s string) f64() f64
f64 returns the value of the string as f64 '1.0'.f64() == f64(1).
fn (s string) fields() []string
fields returns a string array of the string split by \t and
assert '\t\tv = v'.fields() == ['v', '=', 'v']
assert ' sss ssss'.fields() == ['sss', 'ssss']
fn (s string) find_between(start string, end string) string
find_between returns the string found between start string and end string.
assert 'hey [man] how you doin'.find_between('[', ']') == 'man'
fn (s &string) free()
free allows for manually freeing the memory occupied by the string
fn (s string) hash() int
hash returns an integer hash of the string.
fn (s string) i16() i16
i16 returns the value of the string as i16 '1'.i16() == i16(1).
fn (s string) i64() i64
i64 returns the value of the string as i64 '1'.i64() == i64(1).
fn (s string) i8() i8
i8 returns the value of the string as i8 '1'.i8() == i8(1).
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 (s string) index_after(p string, start int) int
index_after returns the position of the input string, starting search from start position.
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 (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 (s string) int() int
int returns the value of the string as an integer '1'.int() == 1.
fn (s string) is_capital() bool
is_capital returns true if the first character in the string is a capital letter.
assert 'Hello'.is_capital() == true
fn (s string) is_lower() bool
is_lower returns true if all characters in the string is lowercase.
assert 'hello developer'.is_lower() == true
fn (s string) is_title() bool
is_title returns true if all words of the string is capitalized.
assert 'Hello V Developer'.is_title() == true
fn (s string) is_upper() bool
is_upper returns true if all characters in the string is uppercase.
assert 'HELLO V'.is_upper() == true
fn (s string) last_index(p string) ?int
last_index returns the position of the last occurence of the input string.
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 (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 (s string) repeat(count int) string
repeat returns a new string with count number of copies of the string it was called on.
fn (s string) replace(rep string, with string) string
replace replaces all occurences of rep with the string passed in with.
fn (s string) replace_each(vals []string) string
replace_each replaces all occurences of the string pairs given in vals.
assert 'ABCD'.replace_each(['B','C/','C','D','D','C']) == 'AC/DC'
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 (s string) reverse() string
reverse returns a reversed string.
assert 'Hello V'.reverse() == 'V olleH'
fn (s string) runes() []rune
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.
assert 'A B C'.split(' ') == ['A','B','C']
assert 'DEF'.split('') == ['D','E','F']
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 (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 (s string) starts_with(p string) bool
starts_with returns true if the string starts with p.
fn (s string) str() string
str returns a copy of the string
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 (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 (s string) substr(start int, end int) string
substr returns the string between index positions start and end.
assert 'ABCD'.substr(1,3) == 'BC'
fn (s string) title() string
title returns the string with each word capitalized.
assert 'hello v developer'.title() == 'Hello V Developer'
fn (s string) to_lower() string
to_lower returns the string in all lowercase characters. TODO only works with ASCII
fn (s string) to_upper() string
to_upper returns the string in all uppercase characters.
assert 'Hello V'.to_upper() == 'HELLO V'
fn (_str string) to_wide() &u16
fn (s string) trim(cutset string) string
trim strips any of the characters given in cutset from the start and end of the string.
assert ' ffHello V ffff'.trim(' f') == 'Hello V'
fn (s string) trim_left(cutset string) string
trim_left strips any of the characters given in cutset from the left of the string.
assert 'd Hello V developer'.trim_left(' d') == 'Hello V developer'
fn (s string) trim_prefix(str string) string
trim_prefix strips str from the start of the string.
assert 'WorldHello V'.trim_prefix('World') == 'Hello V'
fn (s string) trim_right(cutset string) string
trim_right strips any of the characters given in cutset from the right of the string.
assert ' Hello V d'.trim_right(' d') == ' Hello V'
fn (s string) trim_space() string
trim_space strips any of , \n, \t, \v, \f, \r from the start and end of the string.
assert ' Hello V '.trim_space() == 'Hello V'
fn (s string) trim_suffix(str string) string
trim_suffix strips str from the end of the string.
assert 'Hello VWorld'.trim_suffix('World') == 'Hello V'
fn (s string) u16() u16
u16 returns the value of the string as u16 '1'.u16() == u16(1).
fn (s string) u32() u32
u32 returns the value of the string as u32 '1'.u32() == u32(1).
fn (s string) u64() u64
u64 returns the value of the string as u64 '1'.u64() == u64(1).
fn (_rune string) utf32_code() int
Convert utf8 to utf32
struct StrIntpCgenData {
pub:
str string
fmt string
d string
}
==================================================================================== storing struct used by cgen
struct StrIntpData {
pub:
str string
fmt u32
d StrIntpMem
}
NOTE: LOW LEVEL struct storing struct passed to V in the C code
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 {
pub:
name string
has_arg bool
arg string
kind AttributeKind
}
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.