Module builtin stdlib

builtin
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
2
Imported by:
0
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

Imported by

This section is empty.

Overview

builtin is a module that is implicitly imported by every V program.

It implements the builtin V types array, string, map.

It also implements builtin functions like println, eprintln, malloc, panic, print_backtrace.

The autogenerated documentation for builtin functions is lacking, so for these functions, please refer to the official V documentation.

Aliases

This section is empty.

Constants

#constant si_s_code

si_s_code   = '0xfe10'

The consts here are utilities for the compiler's "auto_str_methods.v".

They are used to substitute old _STR calls.

FIXME: this const is not released from memory => use a precalculated string const for now.

si_s_code = "0x" + int(StrIntpType.si_s).hex() // code for a simple string.

#constant si_g32_code

si_g32_code = '0xfe0e'

The consts here are utilities for the compiler's "auto_str_methods.v".

They are used to substitute old _STR calls.

FIXME: this const is not released from memory => use a precalculated string const for now.

si_s_code = "0x" + int(StrIntpType.si_s).hex() // code for a simple string.

#constant si_g64_code

si_g64_code = '0xfe0f'

The consts here are utilities for the compiler's "auto_str_methods.v".

They are used to substitute old _STR calls.

FIXME: this const is not released from memory => use a precalculated string const for now.

si_s_code = "0x" + int(StrIntpType.si_s).hex() // code for a simple string.

#constant none__

pub const none__ = IError(&None__{})

#constant wp_sys_wnohang

wp_sys_wnohang     = u64(0x00000001)

#constant wp_sys_wuntraced

wp_sys_wuntraced   = u64(0x00000002)

#constant wp_sys_wstopped

wp_sys_wstopped    = u64(0x00000002)

#constant wp_sys_wexited

wp_sys_wexited     = u64(0x00000004)

#constant wp_sys_wcontinued

wp_sys_wcontinued  = u64(0x00000008)

#constant wp_sys_wnowait

wp_sys_wnowait     = u64(0x01000000) // don't reap, just poll status.

#constant wp_sys___wnothread

wp_sys___wnothread = u64(0x20000000) // don't wait on children of other threads in this group

#constant wp_sys___wall

wp_sys___wall      = u64(0x40000000) // wait on all children, regardless of type

#constant wp_sys___wclone

wp_sys___wclone    = u64(0x80000000) // wait only on non-sigchld children

#constant fcntlf_dupfd

fcntlf_dupfd         = 0x00000000

#constant fcntlf_exlck

fcntlf_exlck         = 0x00000004

#constant fcntlf_getfd

fcntlf_getfd         = 0x00000001

#constant fcntlf_getfl

fcntlf_getfl         = 0x00000003

#constant fcntlf_getlk

fcntlf_getlk         = 0x00000005

#constant fcntlf_getlk64

fcntlf_getlk64       = 0x0000000c

#constant fcntlf_getown

fcntlf_getown        = 0x00000009

#constant fcntlf_getowner_uids

fcntlf_getowner_uids = 0x00000011

#constant fcntlf_getown_ex

fcntlf_getown_ex     = 0x00000010

#constant fcntlf_getsig

fcntlf_getsig        = 0x0000000b

#constant fcntlf_ofd_getlk

fcntlf_ofd_getlk     = 0x00000024

#constant fcntlf_ofd_setlk

fcntlf_ofd_setlk     = 0x00000025

#constant fcntlf_ofd_setlkw

fcntlf_ofd_setlkw    = 0x00000026

#constant fcntlf_owner_pgrp

fcntlf_owner_pgrp    = 0x00000002

#constant fcntlf_owner_pid

fcntlf_owner_pid     = 0x00000001

#constant fcntlf_owner_tid

fcntlf_owner_tid     = 0x00000000

#constant fcntlf_rdlck

fcntlf_rdlck         = 0x00000000

#constant fcntlf_setfd

fcntlf_setfd         = 0x00000002

#constant fcntlf_setfl

fcntlf_setfl         = 0x00000004

#constant fcntlf_setlk

fcntlf_setlk         = 0x00000006

#constant fcntlf_setlk64

fcntlf_setlk64       = 0x0000000d

#constant fcntlf_setlkw

fcntlf_setlkw        = 0x00000007

#constant fcntlf_setlkw64

fcntlf_setlkw64      = 0x0000000e

#constant fcntlf_setown

fcntlf_setown        = 0x00000008

#constant fcntlf_setown_ex

fcntlf_setown_ex     = 0x0000000f

#constant fcntlf_setsig

fcntlf_setsig        = 0x0000000a

#constant fcntlf_shlck

fcntlf_shlck         = 0x00000008

#constant fcntlf_unlck

fcntlf_unlck         = 0x00000002

#constant fcntlf_wrlck

fcntlf_wrlck         = 0x00000001

#constant fcntllock_ex

fcntllock_ex         = 0x00000002

#constant fcntllock_mand

fcntllock_mand       = 0x00000020

#constant fcntllock_nb

fcntllock_nb         = 0x00000004

#constant fcntllock_read

fcntllock_read       = 0x00000040

#constant fcntllock_rw

fcntllock_rw         = 0x000000c0

#constant fcntllock_sh

fcntllock_sh         = 0x00000001

#constant fcntllock_un

fcntllock_un         = 0x00000008

#constant fcntllock_write

fcntllock_write      = 0x00000080

#constant fcntlo_accmode

fcntlo_accmode       = 0x00000003

#constant fcntlo_append

fcntlo_append        = 0x00000400

#constant fcntlo_cloexec

fcntlo_cloexec       = 0x00080000

#constant fcntlo_creat

fcntlo_creat         = 0x00000040

#constant fcntlo_direct

fcntlo_direct        = 0x00004000

#constant fcntlo_directory

fcntlo_directory     = 0x00010000

#constant fcntlo_dsync

fcntlo_dsync         = 0x00001000

#constant fcntlo_excl

fcntlo_excl          = 0x00000080

#constant fcntlo_largefile

fcntlo_largefile     = 0x00008000

#constant fcntlo_ndelay

fcntlo_ndelay        = 0x00000800

#constant fcntlo_noatime

fcntlo_noatime       = 0x00040000

#constant fcntlo_noctty

fcntlo_noctty        = 0x00000100

#constant fcntlo_nofollow

fcntlo_nofollow      = 0x00020000

#constant fcntlo_nonblock

fcntlo_nonblock      = 0x00000800

#constant fcntlo_path

fcntlo_path          = 0x00200000

#constant fcntlo_rdonly

fcntlo_rdonly        = 0x00000000

#constant fcntlo_rdwr

fcntlo_rdwr          = 0x00000002

#constant fcntlo_trunc

fcntlo_trunc         = 0x00000200

#constant fcntlo_wronly

fcntlo_wronly        = 0x00000001

Sum types

This section is empty.

Functions

#fn C.android_print

fn C.android_print(voidptr, &char, []voidptr)

used by Android for (e)println to output to the Android log system / logcat

#fn JS.Array.prototype.constructor

JavaScript
fn JS.Array.prototype.constructor([]any) JS.Array

#fn JS.Promise.all

JavaScript
fn JS.Promise.all(JS.Array) JS.Promise

#fn JS.Promise.allSettled

JavaScript
fn JS.Promise.allSettled(JS.Array) JS.Promise

#fn JS.Promise.prototype.constructor

JavaScriptuse_new
fn JS.Promise.prototype.constructor(JS.Any) JS.Promise

#fn JS.Promise.race

JavaScript
fn JS.Promise.race(JS.Array) JS.Promise

#fn JS.Promise.reject

JavaScript
fn JS.Promise.reject(JS.Any) JS.Promise

#fn JS.Promise.resolve

JavaScript
fn JS.Promise.resolve(JS.Any) JS.Promise

#fn __malloc

unsafe
fn __malloc(size usize) voidptr

#fn bare_print

fn bare_print(buf &byte, len u64)

#fn bare_print

fn bare_print(buf &byte, len u64)

#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

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

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

#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(mut dst &[]u8, src []u8) 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.

NOTE: This is not an array method. It is a function that takes two arrays of bytes.

See also: arrays.copy.

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

#fn eprint

fn eprint(s string)

#fn eprint

JavaScript
fn eprint(s string)

#fn eprint

fn eprint(s string)

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

#fn eprint_ln

fn eprint_ln(s string)

#fn eprintln

fn eprintln(s string)

eprintln prints a message with a line end, to stderr.

#fn eprintln

fn eprintln(s string)

#fn eprintln

JavaScript
fn eprintln(s string)

#fn eprintln

fn eprintln(s string)

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

#fn error

inline
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

inline
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

inline
fn error_with_code(message string, code int) IError

error_with_code returns a default error instance containing the given message and error code.

Example:

if ouch { return error_with_code('an error occurred', 1) }

#fn error_with_code

inline
fn error_with_code(message string, code int) IError

error_with_code returns a default error instance containing the given message and error code.

Example:

if ouch { return error_with_code('an error occurred', 1) }

#fn exit

noreturn
fn exit(code int)

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

#fn exit

JavaScriptnoreturn
fn exit(c int)

Exits the process in node, and halts execution in the browser because process.exit is undefined. Workaround for not having a 'real' way to exit in the browser.

#fn exit

noreturn
fn exit(code int)

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

#fn f32_abs

inline
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

inline
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

inline
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

inline
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 float32_array

JavaScript
fn float32_array(arr []f32) JS.Float32Array

#fn float64_array

JavaScript
fn float64_array(arr []f64) JS.Float64Array

#fn flush_stderr

JavaScript
fn flush_stderr()

#fn flush_stderr

fn flush_stderr()

#fn flush_stdout

JavaScript
fn flush_stdout()

#fn flush_stdout

fn flush_stdout()

#fn free

unsafe
fn free(ptr voidptr)

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

currently does not free any memory.

#fn free

unsafe
fn free(ptr voidptr)

#fn free

unsafe
fn free(ptr voidptr)

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

However, this is a no-op on JS backend

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

provide an empty function when manual memory management is used to simplify leak detection

#fn gc_check_leaks

fn gc_check_leaks()

for leak detection it is advisable to do explicit garbage collections

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

fn i64_str(n0 i64, base int) string

#fn i64_tos

fn i64_tos(buf &byte, len int, n0 i64, base int) string

#fn int16_array

JavaScript
fn int16_array(arr []i16) JS.Int16Array

#fn int32_array

JavaScript
fn int32_array(arr []int) JS.Int32Array

#fn int64_array

JavaScript
fn int64_array(arr []i64) JS.BigInt64Array

#fn int8_array

JavaScript
fn int8_array(arr []i8) JS.Int8Array

#fn isnil

inline
fn isnil(v voidptr) bool

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

#fn isnil

fn isnil(p voidptr) bool

#fn isnil

JavaScript
fn isnil(val voidptr) bool

Check for nil value

#fn isnil

inline
fn isnil(v voidptr) bool

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

#fn js_is_null

JavaScript
fn js_is_null(x JS.Any) bool

#fn js_is_undefined

JavaScript
fn js_is_undefined(x JS.Any) bool

#fn js_node_process

JavaScript
fn js_node_process() JS.node_process

hack to access process properties

#fn js_null

JavaScript
fn js_null() JS.Any

#fn js_throw

JavaScriptnoreturn
fn js_throw(s any)

#fn js_undefined

JavaScript
fn js_undefined() JS.Any

#fn malloc

unsafe
fn malloc(n isize) &u8

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

unsafe
fn malloc(n isize) &byte

#fn malloc

unsafe
fn malloc(n isize) &u8

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 isize) &u8

#fn malloc_uncollectable

unsafe
fn malloc_uncollectable(n isize) &u8

malloc_uncollectable dynamically allocates a n bytes block of memory on the heap, which will NOT be garbage-collected (but its contents will).

#fn mem_copy

fn mem_copy(dest0 voidptr, src0 voidptr, n isize) voidptr

#fn memcpy

unsafe
fn memcpy(dest &C., src &C., n usize) &C.

#fn memcpy

unsafe
fn memcpy(dest &C., src &C., n usize) &C.

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

unsafe
fn memdup_uncollectable(src voidptr, sz int) voidptr

memdup_uncollectable dynamically allocates a sz bytes block of memory on the heap, which will NOT be garbage-collected (but its contents will).

memdup_uncollectable then copies the contents of src into the allocated space and returns a pointer to the newly allocated space.

#fn mm_alloc

fn mm_alloc(size u64) (&byte, Errno)

#fn mm_free

fn mm_free(addr &byte) Errno

#fn mm_pages

fn mm_pages(size u64) u32

#fn panic

noreturn
fn panic(s string)

panic calls the __panic_abort JS panic handler.

#fn panic

noreturn
fn panic(s string)

panic prints a nice error message, then exits the process with exit code of 1.

#fn panic

fn panic(s string)

#fn panic

noreturn
fn panic(s string)

#fn panic

noreturn
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

noreturn
fn panic_error_number(basestr string, errnum int)

panic with a C-API error message matching errnum

#fn panic_lasterr

Windowsnoreturn
fn panic_lasterr(base string)

panic with an error message generated from WinAPI's LastError

#fn panic_lasterr

Linuxnoreturn
fn panic_lasterr()

#fn panic_option_not_set

noreturn
fn panic_option_not_set(s string)

panic_option_not_set is called by V, when you use option error propagation in your main function.

It ends the program with a panic.

#fn panic_result_not_set

noreturn
fn panic_result_not_set(s string)

panic_result_not_set is called by V, when you use result error propagation in your main function It ends the program with a panic.

#fn print

fn print(s string)

print prints a message to stdout. Unlike println stdout is not automatically flushed.

#fn print

fn print(s string)

#fn print

JavaScript
fn print(s string)

#fn print

manualfree
fn print(s string)

print prints a message to stdout. Unlike println stdout is not automatically flushed.

#fn println

fn println(s string)

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

#fn println

fn println(s string)

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

#fn println

fn println(s string)

#fn println

JavaScript
fn println(s string)

#fn println

manualfree
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

<libproc.h>

#fn promise_new[T]

JavaScript
fn promise_new[T](executor fn (fn (T), fn (JS.Any))) Promise[T]

#fn promise_race[T]

JavaScript
fn promise_race[T](promises []Promise[T]) Promise[T]

race returns returns a promise that fulfills or rejects as soon as one of the promises in an iterable fulfills or rejects, with the value or reason from that promise.

#fn promise_reject

JavaScript
fn promise_reject(error JS.Any) Promise[JS.Any]

reject returns promise which was rejected because of specified error

#fn promise_resolve[T]

JavaScript
fn promise_resolve[T](result T) Promise[T]

resolve returns promise which was resolved with specified value

#fn ptr_str

fn ptr_str(ptr voidptr) string

#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 &u8, old_size int, new_size int) &u8

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.

Note: 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

direct_array_accessmanualfree
fn str_intp(data_len int, input_base &StrIntpData) string

interpolation function

#fn str_intp_g32

inline
fn str_intp_g32(in_str string) string

#fn str_intp_g64

inline
fn str_intp_g64(in_str string) string

#fn str_intp_rune

inline
fn str_intp_rune(in_str string) string

#fn str_intp_sq

inline
fn str_intp_sq(in_str string) string

#fn str_intp_sub

manualfree
fn str_intp_sub(base_str string, in_str string) string

replace %% with the in_str

#fn string_eq

fn string_eq(s1 string, s2 string) bool

#fn string_from_wide

unsafe
fn string_from_wide(_wstr &u16) string

string_from_wide creates a V string, encoded in UTF-8, given a windows style string encoded in UTF-16.

#fn string_from_wide2

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

string_from_wide2 creates a V string, encoded in UTF-8, given a windows style string, encoded in UTF-16. It is more efficient, compared to string_from_wide, but it requires you to know the input string length, and to pass it as the second argument.

#fn string_ne

fn string_ne(s1 string, s2 string) bool

#fn strlen

fn strlen(s &byte) int

#fn sys_close

fn sys_close(fd i64) Errno

#fn sys_dup2

fn sys_dup2(oldfd int, newfd int) (i64, Errno)

33 sys_dup2 unsigned int oldfd unsigned int newfd

#fn sys_exit

fn sys_exit(ec int)

60 sys_exit int error_code

#fn sys_fork

fn sys_fork() int

57 sys_fork

#fn sys_getpid

fn sys_getpid() int

39 sys_getpid

#fn sys_getuid

fn sys_getuid() int

102 sys_getuid

#fn sys_madvise

fn sys_madvise(addr voidptr, len u64, advice int) Errno

#fn sys_mmap

fn sys_mmap(addr &byte, len u64, prot Mm_prot, flags Map_flags, fildes u64, off u64) (&byte, Errno)

9 sys_mmap unsigned long addr unsigned long len unsigned long prot unsigned long flags unsigned long fd unsigned long off

#fn sys_munmap

fn sys_munmap(addr voidptr, len u64) Errno

#fn sys_open

fn sys_open(filename &byte, flags i64, mode int) (i64, Errno)

#fn sys_pipe

fn sys_pipe(filedes &int) Errno

22 sys_pipe int *filedes

#fn sys_read

fn sys_read(fd i64, buf &byte, count u64) (i64, Errno)

0 sys_read unsigned int fd char *buf size_t count

#fn sys_sched_yield

fn sys_sched_yield() Errno

24 sys_sched_yield

#fn sys_vfork

fn sys_vfork() int

58 sys_vfork

#fn sys_waitid

fn sys_waitid(which Wi_which, pid int, infop &int, options int, ru voidptr) Errno

247 sys_waitid int which pid_t upid struct siginfo *infop int options struct rusage *ru

#fn sys_write

fn sys_write(fd i64, buf &byte, count u64) (i64, Errno)

1 sys_write unsigned int fd, const char *buf, size_t count

#fn sys_write

fn sys_write(fd i64, buf &byte, count u64) (i64, Errno)

1 sys_write

#fn tos

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

tos creates a V string, given a C style pointer to a 0 terminated block.

Note: the memory block pointed by s is reused, not copied!

It will panic, when the pointer s is 0.

See also tos_clone.

#fn tos

fn tos(s &byte, len int) string

#fn tos

JavaScript
fn tos(jsstr JS.String) string

#fn tos

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

tos creates a V string, given a C style pointer to a 0 terminated block.

Note: 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

fn tos2(s &byte) string

Same as tos, but calculates the length. Called by string(bytes) casts.

Used only internally.

#fn tos2

unsafe
fn tos2(s &u8) string

tos2 creates a V string, given a C style pointer to a 0 terminated block.

Note: 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

fn tos3(s &char) string

#fn tos3

unsafe
fn tos3(s &char) string

tos3 creates a V string, given a C style pointer to a 0 terminated block.

Note: 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 &u8) string

tos4 creates a V string, given a C style pointer to a 0 terminated block.

Note: 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.

Note: 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 &u8) 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 uint16_array

JavaScript
fn uint16_array(arr []u16) JS.Uint16Array

#fn uint32_array

JavaScript
fn uint32_array(arr []u32) JS.Uint32Array

#fn uint64_array

JavaScript
fn uint64_array(arr []u64) JS.BigUint64Array

#fn uint8_array

JavaScript
fn uint8_array(arr []u8) JS.Uint8Array

#fn unwrap

JavaScript
fn unwrap(opt string) string

#fn utf32_decode_to_buffer

manualfreeunsafe
fn utf32_decode_to_buffer(code u32, buf &u8) int

#fn utf32_to_str

fn utf32_to_str(code u32) string

Convert utf32 to utf8 utf32 == Codepoint

#fn utf32_to_str_no_malloc

manualfreeunsafe
fn utf32_to_str_no_malloc(code u32, buf &u8) string

#fn utf8_char_len

JavaScript
fn utf8_char_len(b u8) int

#fn utf8_char_len

fn utf8_char_len(b u8) int

#fn utf8_str_len

JavaScript
fn utf8_str_len(s string) int

#fn utf8_str_len

deprecated:use `string.len_utf8()` insteaddeprecated_after:2022-05-28
fn utf8_str_len(s string) int

utf8_str_len returns the number of runes contained in the string.

#fn utf8_str_visible_length

JavaScript
fn utf8_str_visible_length(s string) int

#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 &u8, n isize) &u8

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

unsafe
fn vcalloc(n isize) &u8

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

fn vcalloc(n isize) &u8

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 isize) &u8

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

inlineunsafe
fn vmemcmp(const_s1 voidptr, const_s2 voidptr, n isize) 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 isize) voidptr

vmemcpy copies n bytes from memory area src to memory area dest.

The memory areas CAN overlap. vmemcpy returns a pointer to dest.

#fn vmemcpy

inlineunsafe
fn vmemcpy(dest voidptr, const_src voidptr, n isize) 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 isize) voidptr

vmemmove copies n bytes from memory area src to memory area dest.

The memory areas CAN overlap. vmemmove returns a pointer to dest.

#fn vmemmove

inlineunsafe
fn vmemmove(dest voidptr, const_src voidptr, n isize) 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 isize) 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 vmemset

inlineunsafe
fn vmemset(s voidptr, c int, n isize) 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

inlineunsafe
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

inlineunsafe
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

Windows
fn winapi_lasterr_str() string

return an error message generated from WinAPI's LastError

#fn winapi_lasterr_str

Linux
fn winapi_lasterr_str() string

These functions are Windows specific - provide dummys for *nix

#fn write

fn write(fd i64, buf &byte, count u64) i64

#fn write

fn write(_fd i64, _buf &byte, _count u64) i64

#fn (&[]string) free

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

#fn ([]string) str

manualfree
fn (a []string) str() string

str returns a string representation of an array of strings

Example:

['a', 'b', 'c'].str() // => "['a', 'b', 'c']".

#fn ([]u8) hex

fn (b []u8) hex() string

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

#fn ([]int) reduce

deprecated:use arrays.fold instead, this function has less flexibility than arrays.folddeprecated_after:2022-10-11
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.

NOTE: It exists as a method on []int types only.

See also arrays.reduce for same name or arrays.fold for same functionality.

#fn ([]u8) clone

fn (b []u8) clone() []u8

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

#fn ([]u8) bytestr

fn (b []u8) bytestr() string

bytestr produces a string from all the bytes in the array.

Note: 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(&u8(array.data)) instead.

#fn ([]u8) byterune

fn (b []u8) byterune() !rune

byterune attempts to decode a sequence of bytes from utf8 to utf32 and return the result as a rune it will produce an error if there are more than four bytes in the array.

#fn ([]rune) string

manualfree
fn (ra []rune) string() string

string converts a rune array to a string

#fn (&[]string) sort_ignore_case

inline
fn (mut s &[]string) sort_ignore_case()

sort_ignore_case sorts the string array using case insesitive comparing.

#fn (&[]string) sort_by_len

inline
fn (mut s &[]string) sort_by_len()

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

#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

inline
fn (s []string) join_lines() string

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

#fn ([]u8) utf8_to_utf32

fn (_bytes []u8) utf8_to_utf32() !rune

convert array of utf8 bytes to single utf32 value will error if more than 4 bytes are submitted

#fn ([]string) str

JavaScript
fn (a []string) str() string

#fn ([]u8) hex

JavaScript
fn (b []u8) hex() string

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

#fn ([]rune) string

JavaScript
fn (ra []rune) string() string

#fn (&[]string) sort

JavaScript
fn (mut s &[]string) sort()

sort sorts the string array.

#fn (&[]string) sort_ignore_case

JavaScript
fn (mut s &[]string) sort_ignore_case()

sort_ignore_case sorts the string array using case insesitive comparing.

#fn (&[]string) sort_by_len

JavaScript
fn (mut s &[]string) sort_by_len()

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

#fn ([]string) join

JavaScript
fn (s []string) join(sep string) string

Structs

#struct array

pub struct array {
pub:
	element_size int // size in bytes of one element in the array.
pub mut:
	data   voidptr
	offset int // in bytes (should be `usize`), to avoid copying data while making slices, unless it starts changing
	len    int // length of the array in elements.
	cap    int // capacity of the array in elements.
	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) ensure_cap

fn (mut a &array) ensure_cap(required int)

Private function. Increases the cap of an array to the required value by copying the data to a new memory location (creating a clone) unless a.cap is already large enough.

#fn (array) repeat

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 (array) repeat_to_depth

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

repeat_to_depth is an unsafe version of repeat that handles multi-dimensional arrays.

It is unsafe to call directly because depth is not checked

#fn (&array) insert

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

insert inserts a value in the array at index i and increases the index of subsequent elements by 1.

This function is type-aware and can insert items of the same or lower dimensionality as the original array. That is, if the original array is []int, then the insert val may be int or []int. If the original array is [][]int, then val may be []int or [][]int. Consider the examples.

Example:

 mut a := [1, 2, 4]
 a.insert(2, 3)          // a now is [1, 2, 3, 4]
 mut b := [3, 4]
 b.insert(0, [1, 2])     // b now is [1, 2, 3, 4]
 mut c := [[3, 4]]
 c.insert(0, [1, 2])     // c now is [[1, 2], [3, 4]]

#fn (&array) insert_many

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

insert_many is used internally to implement inserting many values into an the array beginning at i.

#fn (&array) prepend

fn (mut a &array) prepend(val voidptr)

prepend prepends one or more elements to an array.

It is shorthand for .insert(0, val)

#fn (&array) prepend_many

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

prepend_many prepends another array to this array.

NOTE: prepend is probably all you need.

NOTE: This code is never called in all of vlib

#fn (&array) delete

fn (mut a &array) delete(i int)

delete deletes array element at index i.

This is exactly the same as calling .delete_many(i, 1).

NOTE: This function does NOT operate in-place. Internally, it creates a copy of the array, skipping over the element at i, and then points the original variable to the new memory location.

Example:

 mut a := ['0', '1', '2', '3', '4', '5']
 a.delete(1) // a is now ['0', '2', '3', '4', '5']

#fn (&array) delete_many

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

delete_many deletes size elements beginning with index i NOTE: This function does NOT operate in-place. Internally, it creates a copy of the array, skipping over size elements starting at i, and then points the original variable to the new memory location.

Example:

 mut a := [1, 2, 3, 4, 5, 6, 7, 8, 9]
 b := a[..9] // creates a <code>[slice](/standard_library/builtin.html#array_slice)</code> of `a`, not a clone
 a.delete_many(4, 3) // replaces `a` with a modified clone
 dump(a) // a: [1, 2, 3, 4, 8, 9] // `a` is now different
 dump(b) // b: [1, 2, 3, 4, 5, 6, 7, 8, 9] // `b` is still the same

#fn (&array) clear

fn (mut a &array) clear()

clear clears the array without deallocating the allocated data.

It does it by setting the array length to 0

Example:

a.clear() // `a.len` is now 0

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

Example:

a.trim(3) // `a.len` is now <= 3

#fn (&array) drop

fn (mut a &array) drop(num int)

drop advances the array past the first num elements whilst preserving spare capacity.

If num is greater than len the array will be emptied.

Example:

 mut a := [1,2]
 a << 3
 a.drop(2)
 assert a == [3]
 assert a.cap > a.len

#fn (array) get_unsafe

inlineunsafe
fn (a array) get_unsafe(i int) voidptr

we manually inline this for single operations for performance without -prod

#fn (array) get

fn (a array) get(i int) voidptr

Private function. Used to implement array[] operator.

#fn (array) get_with_check

fn (a array) get_with_check(i int) voidptr

Private function. Used to implement x = a[i] or { ... }

#fn (array) first

fn (a array) first() voidptr

first returns the first element of the array.

If the array is empty, this will panic.

However, a[0] returns an error object so it can be handled with an or block.

#fn (array) last

fn (a array) last() voidptr

last returns the last element of the array.

If the array is empty, this will panic.

#fn (&array) pop

fn (mut a &array) pop() voidptr

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

If the array is empty, this will panic.

NOTE: this function reduces the length of the given array, but arrays sliced from this one will not change. They still retain their "view" of the underlying memory.

Example:

 mut a := [1, 2, 3, 4, 5, 6, 7, 8, 9]
 b := a[..9] // creates a "view" into the same memory
 c := a.pop() // c == 9
 a[1] = 5
 dump(a) // a: [1, 5, 3, 4, 5, 6, 7, 8]
 dump(b) // b: [1, 5, 3, 4, 5, 6, 7, 8, 9]

#fn (&array) delete_last

fn (mut a &array) delete_last()

delete_last efficiently deletes the last element of the array.

It does it simply by reducing the length of the array by 1.

If the array is empty, this will panic.

See also: trim

#fn (array) slice

fn (a array) slice(start int, _end int) array

slice returns an array using the same buffer as original array but starting from the start element and ending with the element before the end element of the original array with the length and capacity set to the number of the elements in the slice.

It will remain tied to the same memory location until the length increases (copy on grow) or clone is called on it.

If start and end are invalid this function will panic.

Alternative: Slices can also be made with [start..end] notation Alternative: slice_ni will always return an array.

#fn (array) slice_ni

fn (a array) slice_ni(_start int, _end int) array

slice_ni returns an array using the same buffer as original array but starting from the start element and ending with the element before the end element of the original array.

This function can use negative indexes a.slice_ni(-3, a.len) that get the last 3 elements of the array otherwise it return an empty array.

This function always return a valid array.

#fn (array) slice2

fn (a array) slice2(start int, _end int, end_max bool) array

used internally for [2..4]

#fn (array) clone_static_to_depth

fn (a array) clone_static_to_depth(depth int) array

clone_static_to_depth() returns an independent copy of a given array.

Unlike clone_to_depth it has a value receiver and is used internally for slice-clone expressions like a[2..4].clone() and in -autofree generated code.

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

inlineunsafe
fn (mut a &array) set_unsafe(i int, val voidptr)

we manually inline this for single operations for performance without -prod

#fn (&array) set

fn (mut a &array) set(i int, val voidptr)

Private function. Used to implement assignment to the array element.

#fn (&array) push

fn (mut a &array) push(val voidptr)

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

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.

Ignore the function signature. filter does not take an actual callback. Rather, it takes an it expression.

Certain array functions (filter any all) support a simplified domain-specific-language by the backend compiler to make these operations more idiomatic to V. These functions are described here, but their implementation is compiler specific.

Each function takes a boolean test expression as its single argument.

These test expressions may use it as a pointer to a single element at a time.

Example:

array.filter(it < 5) // create an array of elements less than 5

Example:

array.filter(it % 2 == 1) // create an array of only odd elements

Example:

array.filter(it.name[0] == `A`) // create an array of elements whose `name` field starts with 'A'

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

Ignore the function signature. any does not take an actual callback. Rather, it takes an it expression.

It returns true if it finds an element passing the test. Otherwise, it returns false. It doesn't modify the array.

Example:

array.any(it % 2 == 1) // will return true if any element is odd

Example:

array.any(it.name == 'Bob') // will yield `true` if any element has `.name == 'Bob'

#fn (array) all

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

all tests whether all elements in the array pass the test.

Ignore the function signature. all does not take an actual callback. Rather, it takes an it expression.

It returns false if any element fails the test. Otherwise, it returns true. It doesn't modify the array.

Example:

array.all(it % 2 == 1) // will return true if every element is odd

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

It also accepts an it expression.

Example:

 words := ['hello', 'world']
 r1 := words.map(it.to_upper())
 assert r1 == ['HELLO', 'WORLD']
 

// map can also accept anonymous functions
 r2 := words.map(fn (w string) string {
    return w.to_upper()
 })
 assert r2 == ['HELLO', 'WORLD']

#fn (&array) sort

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

sort sorts the array in place.

Ignore the function signature. Passing a callback to sort is not supported for now. Consider using the sort_with_compare method if you need it.

sort can take a boolean test expression as its single argument.

The expression uses 2 'magic' variables a and b as pointers to the two elements being compared.

Example:

array.sort() // will sort the array in ascending order

Example:

array.sort(b < a) // will sort the array in decending order

Example:

array.sort(b.name < a.name) // will sort descending by the .name field

#fn (&array) sort_with_compare

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

sort_with_compare sorts the array in-place using the results of the given function to determine sort order.

The function should return one of three values:

  • -1 when a should come before b ( a < b )

  • 1 when b should come before a ( b < a )

  • 0 when the order cannot be determined ( a == b )

Example:

 fn main() {
    mut a := ['hi', '1', '5', '3']
    a.sort_with_compare(fn (a &string, b &string) int {
        if a < b {
            return -1
        }
        if a > b {
            return 1
        }
        return 0
    })
    assert a == ['1', '3', '5', 'hi']
 }

#fn (array) contains

fn (a array) contains(value voidptr) bool

contains determines whether an array includes a certain value among its elements It will return true if the array contains an element with this value.

It is similar to any but does not take an it expression.

Example:

[1, 2, 3].contains(4) == false

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

Internally, it does this by copying the entire array to a new memory location (creating a clone).

#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 Internally, it does this by copying the entire array to a new memory location (creating a clone) unless the array.cap is already large enough.

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

#fn (&array) ensure_cap_noscan

fn (mut a &array) ensure_cap_noscan(required int)

Private function. Doubles array capacity if needed.

#fn (array) repeat_to_depth_noscan

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

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

#fn (&array) insert_noscan

fn (mut a &array) insert_noscan(i int, val voidptr)

insert inserts a value in the array at index i

#fn (&array) insert_many_noscan

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

insert_many inserts many values into the array from index i.

#fn (&array) prepend_noscan

fn (mut a &array) prepend_noscan(val voidptr)

prepend prepends one value to the array.

#fn (&array) prepend_many_noscan

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

prepend_many prepends another array to this array.

#fn (&array) pop_noscan

fn (mut a &array) pop_noscan() voidptr

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

#fn (array) clone_static_to_depth_noscan

fn (a array) clone_static_to_depth_noscan(depth int) array

clone_static_to_depth_noscan returns an independent copy of a given array.

Unlike clone_to_depth_noscan it has a value receiver and is used internally for slice-clone expressions like a[2..4].clone() and in -autofree generated code.

#fn (&array) clone_to_depth_noscan

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

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

#fn (&array) push_noscan

fn (mut a &array) push_noscan(val voidptr)

#fn (&array) push_many_noscan

unsafe
fn (mut a3 &array) push_many_noscan(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_noscan

fn (a array) reverse_noscan() array

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

#fn (&array) grow_cap_noscan

fn (mut a &array) grow_cap_noscan(amount int)

grow_cap grows the array's capacity by amount elements.

#fn (&array) grow_len_noscan

unsafe
fn (mut a &array) grow_len_noscan(amount int)

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

#fn (&array) trim

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

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

#fn (array) last

JavaScript
fn (a array) last() voidptr

last returns the last element of the array.

#fn (array) get

JavaScript
fn (a array) get(ix int) voidptr

#fn (array) repeat

JavaScript
fn (a array) repeat(count int) array

#fn (&array) set_len

JavaScript
fn (a &array) set_len(i int)

#fn (&array) sort_with_compare

JavaScript
fn (mut a &array) sort_with_compare(compare voidptr)

#fn (&array) sort_with_compare_old

JavaScript
fn (mut a &array) sort_with_compare_old(compare voidptr)

#fn (&array) sort

JavaScript
fn (mut a &array) sort()

#fn (array) index

JavaScript
fn (a array) index(v string) int

#fn (array) slice

JavaScript
fn (a array) slice(start int, end int) array

#fn (&array) insert

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

#fn (&array) insert_many

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

#fn (&array) push

JavaScript
fn (mut a &array) push(val voidptr)

#fn (&array) delete

JavaScript
fn (mut a &array) delete(i int)

delete deletes array element at index i.

#fn (&array) delete_many

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

delete_many deletes size elements beginning with index i

#fn (&array) prepend

JavaScript
fn (mut a &array) prepend(val voidptr)

prepend prepends one value to the array.

#fn (&array) prepend_many

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

prepend_many prepends another array to this array.

#fn (array) reverse

JavaScript
fn (a array) reverse() array

#fn (&array) reverse_in_place

JavaScript
fn (mut a &array) reverse_in_place()

#fn (&array) clear

JavaScript
fn (mut a &array) clear()

#fn (array) reduce

JavaScript
fn (a array) 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 (&array) pop

JavaScript
fn (mut a &array) pop() voidptr

#fn (array) first

JavaScript
fn (a array) first() voidptr

#fn (array) contains

JavaScript
fn (a array) contains(key voidptr) bool

#fn (&array) delete_last

JavaScript
fn (mut a &array) delete_last()

delete_last effectively removes last element of an array.

#fn (&array) free

JavaScriptunsafe
fn (a &array) free()

#fn (array) bytestr

JavaScript
fn (a array) bytestr() string

todo: once (a []u8) will work rewrite this

#fn (array) to_js_array

JavaScript
fn (a array) to_js_array() JS.Array

#fn (array) to_number_array

JavaScript
fn (a array) to_number_array() JS.Array

#fn (array) get

fn (a array) get(i int) voidptr

Private function. Used to implement array[] operator

#fn (&array) set

fn (mut a &array) set(i int, val voidptr)

Private function. Used to implement assignment to the array element.

#fn (array) repeat

fn (a array) repeat(nr_repeats int) array

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

#struct VAssertMetaInfo

pub struct VAssertMetaInfo {
pub:
	fpath   string // the source file path of the assertion
	line_nr int    // the line number of the assertion
	fn_name string // the function name in which the assertion is
	src     string // the actual source line of the assertion
	op      string // the operation of the assertion, i.e. '==', '<', 'call', etc ...
	llabel  string // the left side of the infix expressions as source
	rlabel  string // the right side of the infix expressions as source
	lvalue  string // the stringified *actual value* of the left side of a failed assertion
	rvalue  string // the stringified *actual value* of the right side of a failed assertion
	message string // the value of the `message` from `assert cond, message`
	has_msg bool   // false for assertions like `assert cond`, true for `assert cond, 'oh no'`
}

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

#fn (&VAssertMetaInfo) free

manualfreeunsafe
fn (ami &VAssertMetaInfo) free()

free frees the memory occupied by the assertion meta data. It is called automatically by the code, that V's test framework generates, after all other callbacks have been called.

#struct MethodArgs

pub struct MethodArgs {
pub:
	typ  int
	name string
}

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

#struct FunctionData

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

FunctionData holds information about a parsed function.

#struct EnumData

pub struct EnumData {
pub:
	name  string
	value i64
}

#struct FieldData

pub struct FieldData {
pub:
	name          string // the name of the field f
	typ           int    // the internal TypeID of the field f,
	unaliased_typ int    // if f's type was an alias of int, this will be TypeID(int)
	//
	attrs  []string // the attributes of the field f
	is_pub bool     // f is in a `pub:` section
	is_mut bool     // f is in a `mut:` section
	//
	is_shared bool // `f shared Abc`
	is_atomic bool // `f atomic int` , TODO
	is_option bool // `f ?string` , TODO
	//
	is_array  bool // `f []string` , TODO
	is_map    bool // `f map[string]int` , TODO
	is_chan   bool // `f chan int` , TODO
	is_enum   bool // `f Enum` where Enum is an enum
	is_struct bool // `f Abc` where Abc is a struct , TODO
	is_alias  bool // `f MyInt` where `type MyInt = int`, TODO
	//
	indirections u8 // 0 for `f int`, 1 for `f &int`, 2 for `f &&int` , TODO
}

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

#struct StructAttribute

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

#struct SymbolInfo

Windows
pub struct SymbolInfo {
pub mut:
	f_size_of_struct u32 // must be 88 to be recognised by SymFromAddr
	f_type_index     u32 // Type Index of symbol
	f_reserved       [2]u64
	f_index          u32
	f_size           u32
	f_mod_base       u64 // Base Address of module comtaining this symbol
	f_flags          u32
	f_value          u64 // Value of symbol, ValuePresent should be 1
	f_address        u64 // Address of symbol including base address of module
	f_register       u32 // register holding value or pointer to value
	f_scope          u32 // scope of the symbol
	f_tag            u32 // pdb classification
	f_name_len       u32 // Actual length of name
	f_max_name_len   u32 // must be manually set
	f_name           u8  // must be calloc(f_max_name_len)
}

SymbolInfo is used by print_backtrace_skipping_top_frames_msvc

#struct SymbolInfoContainer

Windows
pub struct SymbolInfoContainer {
pub mut:
	syminfo     SymbolInfo
	f_name_rest [254]char
}

#struct Line64

Windows
pub struct Line64 {
pub mut:
	f_size_of_struct u32
	f_key            voidptr
	f_line_number    u32
	f_file_name      &u8 = unsafe { nil }
	f_address        u64
}

#struct map

pub struct map {
	// Number of bytes of a key
	key_bytes int
	// Number of bytes of a value
	value_bytes int
mut:
	// Highest even index in the hashtable
	even_index u32
	// Number of cached hashbits left for rehashing
	cached_hashbits u8
	// Used for right-shifting out used hashbits
	shift u8
	// Array storing key-values (ordered)
	key_values DenseArray
	// Pointer to meta-data:
	// - Odd indices store kv_index.
	// - Even indices store probe_count and hashbits.
	metas &u32
	// Extra metas that allows for no ranging when incrementing
	// index in the hashmap
	extra_metas     u32
	has_string_keys bool
	hash_fn         MapHashFn
	key_eq_fn       MapEqFn
	clone_fn        MapCloneFn
	free_fn         MapFreeFn
pub mut:
	// Number of key-values currently in the hashmap
	len int
}

map is the internal representation of a V map type.

#fn new_map

fn new_map(key_bytes int, value_bytes int, hash_fn fn (voidptr) u64, key_eq_fn fn (voidptr, voidptr) bool, clone_fn fn (voidptr, voidptr), free_fn fn (voidptr)) map

#fn (map[string]toml.Any) value

fn (m map[string]toml.Any) value(key string) toml.Any

value queries a value from the map.

key supports a small query syntax scheme:

Maps can be queried in "dotted" form e.g. a.b.c.

quoted keys are supported as a."b.c" or a.'b.c'.

Arrays can be queried with a[0].b[1].[2].

#fn (map[string]toml.Any) as_strings

fn (m map[string]toml.Any) as_strings() map[string]string

as_strings returns the contents of the map as map[string]string

#fn (map[string]toml.Any) to_toml

fn (m map[string]toml.Any) to_toml() string

to_toml returns the contents of the map as a TOML encoded string.

#fn (map[string]toml.Any) to_inline_toml

fn (m map[string]toml.Any) to_inline_toml() string

to_inline_toml returns the contents of the map as an inline table encoded TOML string.

#fn (&map) move

fn (mut m &map) move() map

#fn (&map) clear

fn (mut m &map) clear()

clear clears the map without deallocating the allocated data.

It does it by setting the map length to 0

Example:

a.clear() // `a.len` and `a.key_values.len` is now 0

#fn (&map) key_to_index

inline
fn (m &map) key_to_index(pkey voidptr) (u32, u32)

#fn (&map) meta_less

inline
fn (m &map) meta_less(_index u32, _metas u32) (u32, u32)

#fn (&map) meta_greater

inline
fn (mut m &map) meta_greater(_index u32, _metas u32, kvi u32)

#fn (&map) ensure_extra_metas

inline
fn (mut m &map) ensure_extra_metas(probe_count u32)

#fn (&map) set

fn (mut m &map) set(key voidptr, value voidptr)

Insert new element to the map. The element is inserted if its key is not equivalent to the key of any other element already in the container.

If the key already exists, its value is changed to the value of the new element.

#fn (&map) expand

fn (mut m &map) expand()

Doubles the size of the hashmap

#fn (&map) rehash

fn (mut m &map) rehash()

A rehash is the reconstruction of the hash table:

All the elements in the container are rearranged according to their hash value into the newly sized key-value container.

Rehashes are performed when the load_factor is going to surpass the max_load_factor in an operation.

#fn (&map) reserve

fn (mut m &map) reserve(meta_bytes u32)

reserve memory for the map meta data

#fn (&map) cached_rehash

fn (mut m &map) cached_rehash(old_cap u32)

This method works like rehash. However, instead of rehashing the key completely, it uses the bits cached in metas.

#fn (&map) get_and_set

fn (mut m &map) get_and_set(key voidptr, zero voidptr) voidptr

This method is used for assignment operators. If the argument-key does not exist in the map, it's added to the map along with the zero/default value.

If the key exists, its respective value is returned.

#fn (&map) get

fn (m &map) get(key voidptr, zero voidptr) voidptr

If key matches the key of an element in the container, the method returns a reference to its mapped value.

If not, a zero/default value is returned.

#fn (&map) get_check

fn (m &map) get_check(key voidptr) voidptr

If key matches the key of an element in the container, the method returns a reference to its mapped value.

If not, a zero pointer is returned.

This is used in x := m['key'] or { ... }

#fn (&map) exists

fn (m &map) exists(key voidptr) bool

Checks whether a particular key exists in the 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) values

fn (m &map) values() array

Returns all values 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.

#fn (&map) internal_set

JavaScript
fn (mut m &map) internal_set(key JS.Any, val JS.Any)

#fn (&map) internal_get

JavaScript
fn (mut m &map) internal_get(key JS.Any) JS.Any

#fn (&map) delete

JavaScriptunsafe
fn (mut m &map) delete(key JS.Any)

Removes the mapping of a particular key from the map.

#fn (&map) free

JavaScript
fn (m &map) free()

#fn (map[string]v.doc.DocNode) arr

fn (cnts map[string]v.doc.DocNode) arr() []v.doc.DocNode

arr() converts the map into an array of DocNode.

#fn (map[string]x.json2.Any) str

fn (f map[string]x.json2.Any) str() string

str returns the JSON string representation of the map[string]Any type.

#struct Error

pub struct Error {}

Error is the empty default implementation of IError.

#fn (Error) msg

fn (err Error) msg() string

#fn (Error) code

fn (err Error) code() int

#fn (Error) msg

fn (err Error) msg() string

msg returns the message of Error

#fn (Error) code

fn (err Error) code() int

code returns the code of Error

#struct SortedMap

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

#fn new_sorted_map

fn new_sorted_map(n int, value_bytes int) SortedMap

#fn (&SortedMap) set

fn (mut m &SortedMap) set(key string, value voidptr)

This implementation does proactive insertion, meaning that splits are done top-down and not bottom-up.

#fn (SortedMap) get

fn (m SortedMap) get(key string, out voidptr) bool

#fn (SortedMap) exists

fn (m SortedMap) exists(key string) bool

#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

pub struct string {
pub:
	str &u8 = 0 // points to a C style 0 terminated string of bytes.
	len int // the length of the .str field, excluding the ending 0 byte. It is always equal to strlen(.str).
	// 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.
mut:
	is_lit int
}

#fn (string) runes

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

fn (s string) len_utf8() int

len_utf8 returns the number of runes contained in the string s.

#fn (string) clone_static

inline
fn (a string) clone_static() string

clone_static returns an independent copy of a given array.

It should be used only in -autofree generated code.

#fn (string) clone

fn (a string) clone() string

clone returns a copy of the V string a.

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

direct_array_access
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

direct_array_access
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_char

direct_array_access
fn (s string) replace_char(rep u8, with u8, repeat int) string

replace_char replaces all occurences of the character rep multiple occurences of the character passed in with with respect to repeat.

Example:

assert '\tHello!'.replace_char(`\t`,` `,8) == '        Hello!'

#fn (string) normalize_tabs

inline
fn (s string) normalize_tabs(tab_len int) string

normalize_tabs replaces all tab characters with tab_len amount of spaces

Example:

assert '\t\tpop rax\t; pop rax'.normalize_tabs(2) == '    pop rax  ; pop rax'

#fn (string) bool

inline
fn (s string) bool() bool

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

#fn (string) int

inline
fn (s string) int() int

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

#fn (string) i64

inline
fn (s string) i64() i64

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

#fn (string) i8

inline
fn (s string) i8() i8

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

#fn (string) i16

inline
fn (s string) i16() i16

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

#fn (string) f32

inline
fn (s string) f32() f32

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

#fn (string) f64

inline
fn (s string) f64() f64

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

#fn (string) u8

inline
fn (s string) u8() u8

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

#fn (string) u16

inline
fn (s string) u16() u16

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

#fn (string) u32

inline
fn (s string) u32() u32

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

#fn (string) u64

inline
fn (s string) u64() u64

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

#fn (string) parse_uint

inline
fn (s string) parse_uint(_base int, _bit_size int) !u64

parse_uint is like parse_int but for unsigned numbers

This method directly exposes the parse_uint function from strconv as a method on string. For more advanced features, consider calling strconv.common_parse_uint directly.

#fn (string) parse_int

inline
fn (s string) parse_int(_base int, _bit_size int) !i64

parse_int interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.

If the base argument is 0, the true base is implied by the string's prefix: 2 for "0b", 8 for "0" or "0o", 16 for "0x", and 10 otherwise.

Also, for argument base 0 only, underscore characters are permitted as defined by the Go syntax for integer literals.

The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64.

If bitSize is below 0 or above 64, an error is returned.

This method directly exposes the parse_int function from strconv as a method on string. For more advanced features, consider calling strconv.common_parse_int directly.

#fn (string) operator==

direct_array_access
fn (s string) == (a string) bool

#fn (string) compare

direct_array_access
fn (s string) compare(a string) int

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

#fn (string) operator<

direct_array_access
fn (s string) < (a string) bool

#fn (string) operator+

direct_array_access
fn (s string) + (a string) string

#fn (string) split_any

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

split_any splits the string to an array by any of the delim chars.

Example:

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

Split a string using the chars in the delimiter string as delimiters chars.

If the delimiter string is empty then split is used.

#fn (string) rsplit_any

direct_array_access
fn (s string) rsplit_any(delim string) []string

rsplit_any splits the string to an array by any of the delim chars in reverse order.

Example:

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

Split a string using the chars in the delimiter string as delimiters chars.

If the delimiter string is empty then rsplit is used.

#fn (string) split

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

split splits the string to an array by delim.

Example:

assert 'A B C'.split(' ') == ['A','B','C']

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

Example:

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

#fn (string) rsplit

inline
fn (s string) rsplit(delim string) []string

rsplit splits the string to an array by delim in reverse order.

Example:

assert 'A B C'.rsplit(' ') == ['C','B','A']

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

Example:

assert 'DEF'.rsplit('') == ['F','E','D']

#fn (string) split_once

fn (s string) split_once(delim string) ?(string, string)

split_once devides string into pair of string by delim.

Example:

 path, ext := 'file.ts.dts'.splice_once('.')?


assert path == 'file'
 assert ext == 'ts.dts'

Note that rsplit_once returns splitted string string as first part of pair, and returns remaining as second part of pair.

#fn (string) rsplit_once

fn (s string) rsplit_once(delim string) ?(string, string)

rsplit_once devides string into pair of string by delim.

Example:

 path, ext := 'file.ts.dts'.splice_once('.')?


assert path == 'file.ts'
 assert ext == 'dts'

Note that rsplit_once returns remaining string as first part of pair, and returns splitted string as second part of pair.

#fn (string) split_nth

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

direct_array_access
fn (s string) rsplit_nth(delim string, nth int) []string

rsplit_nth splits the string based on the passed delim substring in revese order.

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

direct_array_access
fn (s string) split_into_lines() []string

split_into_lines splits the string by newline characters.

newlines are stripped.

\r (MacOS), \n (POSIX), and \r\n (WinOS) line endings are all supported (including mixed line endings).

NOTE: algorithm is "greedy", consuming '\r\n' as a single line ending with higher priority than '\r' and '\n' as multiple endings

#fn (string) substr2

inline
fn (s string) substr2(start int, _end int, end_max bool) string

used internally for [2..4]

#fn (string) substr

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

direct_array_access
fn (s string) substr_with_check(start int, end int) !string

version of substr that is used in a[start..end] or { return an error when the index is out of range

#fn (string) substr_ni

direct_array_access
fn (s string) substr_ni(_start int, _end int) string

substr_ni returns the string between index positions start and end allowing negative indexes This function always return a valid string.

#fn (string) index_

direct_array_access
fn (s string) index_(p string) int

index returns the position of the first character of the input string.

It will return -1 if the input string can't be found.

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

direct_array_accessmanualfree
fn (s string) index_kmp(p string) int

index_kmp does KMP search.

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

direct_array_access
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

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

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

#fn (string) index_after

direct_array_access
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_u8

direct_array_access
fn (s string) index_u8(c u8) int

index_u8 returns the index of byte c if found in the string.

index_u8 returns -1 if the byte can not be found.

#fn (string) last_index_u8

direct_array_access
fn (s string) last_index_u8(c u8) 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) count

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

fn (s string) contains_u8(x u8) bool

contains_u8 returns true if the string contains the byte value x.

See also: string.index_u8 , to get the index of the byte as well.

#fn (string) contains

fn (s string) contains(substr string) bool

contains returns true if the string contains substr.

See also: string.index

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

fn (s string) contains_only(chars string) bool

contains_only returns true, if the string contains only the characters 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) starts_with

direct_array_access
fn (s string) starts_with(p string) bool

starts_with returns true if the string starts with p.

#fn (string) ends_with

direct_array_access
fn (s string) ends_with(p string) bool

ends_with returns true if the string ends with p.

#fn (string) to_lower

direct_array_access
fn (s string) to_lower() string

to_lower returns the string in all lowercase characters.

TODO only works with ASCII

#fn (string) is_lower

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

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

direct_array_access
fn (s string) is_upper() bool

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

See also: byte.is_capital

Example:

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

#fn (string) capitalize

direct_array_access
fn (s string) capitalize() string

capitalize returns the string with the first character capitalized.

Example:

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

#fn (string) is_capital

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

Example:

assert 'Hello'.is_capital() == true

Example:

assert 'HelloWorld'.is_capital() == false

#fn (string) starts_with_capital

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

Example:

assert 'Hello'.starts_with_capital() == true

Example:

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

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

inline
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

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_indexes

direct_array_access
fn (s string) trim_indexes(cutset string) (int, int)

trim_indexes gets the new start and end indicies of a string when any of the characters given in cutset were stripped from the start and end of the string. Should be used as an input to substr. If the string contains only the characters in cutset, both values returned are zero.

Example:

left, right := '-hi-'.trim_indexes('-')

#fn (string) trim_left

direct_array_access
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_right

direct_array_access
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_string_left

fn (s string) trim_string_left(str string) string

trim_string_left strips str from the start of the string.

Example:

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

#fn (string) trim_string_right

fn (s string) trim_string_right(str string) string

trim_string_right strips str from the end of the string.

Example:

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

#fn (string) trim_prefix

deprecated:use s.trim_string_left(x) insteaddeprecated_after:2022-01-19
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_suffix

deprecated:use s.trim_string_right(x) insteaddeprecated_after:2022-01-19
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) str

inline
fn (s string) str() string

str returns a copy of the string

#fn (string) at

fn (s string) at(idx int) byte

at returns the byte at index idx.

Example:

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

#fn (string) at_with_check

fn (s string) at_with_check(idx int) ?u8

version of at that is used in a[i] or { return an error when the index is out of range

#fn (&string) free

manualfreeunsafe
fn (s &string) free()

free allows for manually freeing the memory occupied by the string

#fn (string) before

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.

Example:

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

Example:

assert 'abcd'.before('.') == 'abcd'

TODO: deprecate and remove either .before or .all_before

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

Example:

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

Example:

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.

Example:

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

Example:

assert 'abcd'.all_before_last('.') == '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.

Example:

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

Example:

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.

Example:

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

Example:

assert 'abcd'.all_after_last('z') == 'abcd'

#fn (string) all_after_first

fn (s string) all_after_first(sub string) string

all_after_first returns the contents after the first occurence of sub in the string.

If the substring is not found, it returns the full input string.

Example:

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

Example:

assert 'abcd'.all_after_first('z') == 'abcd'

#fn (string) after

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

Example:

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

Example:

assert 'abcd'.after('z') == 'abcd'

TODO: deprecate either .all_after_last or .after

#fn (string) after_char

fn (s string) after_char(sub u8) 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.

Example:

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

Example:

assert 'abcd'.after_char(`:`) == 'abcd'

#fn (string) reverse

direct_array_access
fn (s string) reverse() string

reverse returns a reversed string.

Example:

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

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

fn (s string) hash() int

hash returns an integer hash of the string.

#fn (string) bytes

fn (s string) bytes() []u8

bytes returns the string converted to a byte array.

#fn (string) repeat

direct_array_access
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) 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']

Example:

assert '  sss   ssss'.fields() == ['sss', 'ssss']

#fn (string) strip_margin

inline
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 ``.

See also: string.trim_indent()

Example:

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

assert st == 'Hello there,
   this is a string,
   Everything before the first | is removed'

#fn (string) strip_margin_custom

direct_array_access
fn (s string) strip_margin_custom(del u8) string

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

#fn (string) trim_indent

fn (s string) trim_indent() string

trim_indent detects a common minimal indent of all the input lines, removes it from every line and also removes the first and the last lines if they are blank (notice difference blank vs empty).

Note that blank lines do not affect the detected indent level.

In case if there are non-blank lines with no leading whitespace characters (no indent at all) then the common indent is 0, and therefore this function doesn't change the indentation.

Example:

 st := '
      Hello there,
      this is a string,
      all the leading indents are removed
      and also the first and the last lines if they are blank
 '.trim_indent()
 

assert st == 'Hello there,
 this is a string,
 all the leading indents are removed
 and also the first and the last lines if they are blank'

#fn (string) indent_width

fn (s string) indent_width() int

indent_width returns the number of spaces or tabs at the beginning of the string.

Example:

assert '  v'.indent_width() == 2

Example:

assert '\t\tv'.indent_width() == 2

#fn (string) is_blank

fn (s string) is_blank() bool

is_blank returns true if the string is empty or contains only white-space.

Example:

assert ' '.is_blank()

Example:

assert '\t'.is_blank()

Example:

assert 'v'.is_blank() == false

#fn (string) match_glob

direct_array_access
fn (name string) match_glob(pattern string) bool

match_glob matches the string, with a Unix shell-style wildcard pattern.

Note: wildcard patterns are NOT the same as regular expressions.

They are much simpler, and do not allow backtracking, captures, etc.

The special characters used in shell-style wildcards are:

* - matches everything ? - matches any single character [seq] - matches any of the characters in the sequence [^seq] - matches any character that is NOT in the sequence Any other character in pattern, is matched 1:1 to the corresponding character in name, including / and .

You can wrap the meta-characters in brackets too, i.e. [?] matches ? in the string, and [*] matches * in the string.

Example:

assert 'ABCD'.match_glob('AB*')

Example:

assert 'ABCD'.match_glob('*D')

Example:

assert 'ABCD'.match_glob('*B*')

Example:

assert !'ABCD'.match_glob('AB')

#fn (string) is_ascii

inline
fn (s string) is_ascii() bool

is_ascii returns true if all characters belong to the US-ASCII set ([ ..~])

#fn (string) to_wide

fn (_str string) to_wide() &u16

to_wide returns a pointer to an UTF-16 version of the string receiver.

In V, strings are encoded using UTF-8 internally, but on windows most APIs, that accept strings, need them to be in UTF-16 encoding.

The returned pointer of .to_wide(), has a type of &u16, and is suitable for passing to Windows APIs that expect LPWSTR or wchar_t* parameters.

See also MultiByteToWideChar ( https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar )

#fn (string) utf32_code

fn (_rune string) utf32_code() int

Convert utf8 to utf32 the original implementation did not check for valid utf8 in the string, and could result in values greater than the utf32 spec it has been replaced by utf8_to_utf32 which has an option return type.

this function is left for backward compatibility it is used in vlib/builtin/string.v, and also in vlib/v/gen/c/cgen.v

#fn (string) runes

JavaScript
fn (s string) runes() []rune

#fn (string) slice

JavaScript
fn (s string) slice(a int, b int) string

#fn (string) substr

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

#fn (string) after

JavaScript
fn (s string) after(dot string) string

#fn (string) after_char

JavaScript
fn (s string) after_char(dot u8) string

#fn (string) all_after

JavaScript
fn (s string) all_after(dot string) string

#fn (string) all_after_last

JavaScript
fn (s string) all_after_last(dot string) string

why does this exist?

#fn (string) all_before

JavaScript
fn (s string) all_before(dot string) string

#fn (string) all_before_last

JavaScript
fn (s string) all_before_last(dot string) string

#fn (string) bool

JavaScript
fn (s string) bool() bool

#fn (string) split

JavaScript
fn (s string) split(dot string) []string

#fn (string) bytes

JavaScript
fn (s string) bytes() []u8

#fn (string) capitalize

JavaScript
fn (s string) capitalize() string

#fn (string) clone

JavaScript
fn (s string) clone() string

#fn (string) contains

JavaScript
fn (s string) contains(substr string) bool

#fn (string) contains_any

JavaScript
fn (s string) contains_any(chars string) bool

#fn (string) contains_any_substr

JavaScript
fn (s string) contains_any_substr(chars []string) bool

#fn (string) count

JavaScript
fn (s string) count(substr string) int

#fn (string) ends_with

JavaScript
fn (s string) ends_with(p string) bool

#fn (string) starts_with

JavaScript
fn (s string) starts_with(p string) bool

#fn (string) fields

JavaScript
fn (s string) fields() []string

#fn (string) find_between

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

#fn (&string) free

JavaScript
fn (s &string) free()

unnecessary in the JS backend, implemented for api parity.

#fn (string) hash

JavaScript
fn (s string) hash() int

#fn (string) int

JavaScript
fn (s string) int() int

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

#fn (string) i64

JavaScript
fn (s string) i64() i64

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

#fn (string) i8

JavaScript
fn (s string) i8() i8

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

#fn (string) i16

JavaScript
fn (s string) i16() i16

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

#fn (string) f32

JavaScript
fn (s string) f32() f32

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

#fn (string) f64

JavaScript
fn (s string) f64() f64

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

#fn (string) u16

JavaScript
fn (s string) u16() u16

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

#fn (string) u32

JavaScript
fn (s string) u32() u32

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

#fn (string) u64

JavaScript
fn (s string) u64() u64

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

#fn (string) u8

JavaScript
fn (s string) u8() u64

#fn (string) trim_right

JavaScript
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_left

JavaScriptdirect_array_access
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_string_left

JavaScript
fn (s string) trim_string_left(str string) string

trim_string_left strips str from the start of the string.

Example:

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

#fn (string) trim_string_right

JavaScript
fn (s string) trim_string_right(str string) string

trim_string_right strips str from the end of the string.

Example:

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

#fn (string) trim_prefix

JavaScriptdeprecated:use s.trim_string_left(x) insteaddeprecated_after:2022-01-19
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_suffix

JavaScriptdeprecated:use s.trim_string_right(x) insteaddeprecated_after:2022-01-19
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) at

JavaScript
fn (s string) at(idx int) u8

at returns the byte at index idx.

Example:

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

#fn (string) to_lower

JavaScript
fn (s string) to_lower() string

#fn (string) replace

JavaScript
fn (s string) replace(old_sub string, new_sub string) string

TODO: check if that behaves the same as V's own string.replace(old_sub,new_sub):

#fn (string) to_upper

JavaScript
fn (s string) to_upper() string

#fn (string) str

JavaScript
fn (s string) str() string

str returns a copy of the string

#fn (string) repeat

JavaScript
fn (s string) repeat(count int) string

#fn (string) strip_margin

JavaScript
fn (s string) strip_margin() string

TODO: Make these functions actually work.

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

JavaScriptdirect_array_access
fn (s string) strip_margin_custom(del u8) string

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

#fn (string) split_nth

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

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

JavaScript
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

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

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

#fn (string) trim_space

JavaScript
fn (s string) trim_space() string

#fn (string) index_after

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

#fn (string) split_into_lines

JavaScript
fn (s string) split_into_lines() []string

#fn (string) replace_once

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

JavaScript
fn (s string) title() string

#fn (string) index_any

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

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

JavaScript
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_capital

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

Example:

assert 'Hello'.is_capital() == true

Example:

assert 'HelloWorld'.is_capital() == false

#fn (string) starts_with_capital

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

Example:

assert 'Hello'.starts_with_capital() == true

Example:

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

#fn (string) is_upper

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

JavaScript
fn (s string) is_lower() bool

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

Example:

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

#fn (string) reverse

JavaScript
fn (s string) reverse() string

#fn (string) trim

JavaScript
fn (s string) trim(cutset string) string

#fn (string) index

JavaScript
fn (s string) index(search 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) utf32_code

JavaScript
fn (_rune string) utf32_code() int

#fn (string) compare

JavaScript
fn (s string) compare(a string) int

#fn (string) add

fn (s string) add(a string) string

#fn (string) clone

fn (a string) clone() string

#union StrIntpMem

pub 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 used by StrIntpData

#struct StrIntpCgenData

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

storing struct used by cgen

#struct StrIntpData

pub struct StrIntpData {
pub:
	str string
	// fmt     u64  // expanded version for future use, 64 bit
	fmt u32
	d   StrIntpMem
}

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

#fn (&StrIntpData) process_str_intp_data

manualfree
fn (data &StrIntpData) process_str_intp_data(mut sb &strings.Builder)

convert from struct to formated string

#struct Error

pub struct Error {}

Error is the empty default implementation of IError.

#fn (Error) msg

fn (err Error) msg() string

#fn (Error) code

fn (err Error) code() int

#fn (Error) msg

fn (err Error) msg() string

msg returns the message of Error

#fn (Error) code

fn (err Error) code() int

code returns the code of Error

#struct Option

pub struct Option {
	state u8
	err   IError = none__
}

#fn (Option) str

fn (o Option) str() string

str returns the Option type: ok, none, or error

#struct _option

pub struct _option {
	state u8
	err   IError = none__
}

#fn (_option) str

fn (o _option) str() string

str returns the Option type: ok, none, or error

#struct JS.node_process

JavaScript
pub struct JS.node_process {
pub:
	arch     string
	argsv    []string
	env      []string
	platform string
	version  string
	// TODO: add all properties
}

#struct Promise[T]

JavaScript
pub struct Promise[T] {
mut:
	promise JS.Promise [noinit]
}

The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.

#fn (Promise[T]) then

JavaScript
fn (p Promise[T]) then(on_fullfilled fn (T), on_rejected fn (JS.Any))

#fn (Promise[T]) catch

JavaScript
fn (p Promise[T]) catch(callback fn (JS.Any)) Promise[T]

catch method returns a Promise and deals with rejected cases only.

#fn (Promise[T]) finally[U]

JavaScript
fn (p Promise[T]) finally(callback fn ()) Promise[JS.Any]

#struct string

JavaScript
pub struct string {
pub:
	str JS.String
	len int
}

#fn (string) runes

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

fn (s string) len_utf8() int

len_utf8 returns the number of runes contained in the string s.

#fn (string) clone_static

inline
fn (a string) clone_static() string

clone_static returns an independent copy of a given array.

It should be used only in -autofree generated code.

#fn (string) clone

fn (a string) clone() string

clone returns a copy of the V string a.

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

direct_array_access
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

direct_array_access
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_char

direct_array_access
fn (s string) replace_char(rep u8, with u8, repeat int) string

replace_char replaces all occurences of the character rep multiple occurences of the character passed in with with respect to repeat.

Example:

assert '\tHello!'.replace_char(`\t`,` `,8) == '        Hello!'

#fn (string) normalize_tabs

inline
fn (s string) normalize_tabs(tab_len int) string

normalize_tabs replaces all tab characters with tab_len amount of spaces

Example:

assert '\t\tpop rax\t; pop rax'.normalize_tabs(2) == '    pop rax  ; pop rax'

#fn (string) bool

inline
fn (s string) bool() bool

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

#fn (string) int

inline
fn (s string) int() int

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

#fn (string) i64

inline
fn (s string) i64() i64

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

#fn (string) i8

inline
fn (s string) i8() i8

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

#fn (string) i16

inline
fn (s string) i16() i16

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

#fn (string) f32

inline
fn (s string) f32() f32

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

#fn (string) f64

inline
fn (s string) f64() f64

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

#fn (string) u8

inline
fn (s string) u8() u8

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

#fn (string) u16

inline
fn (s string) u16() u16

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

#fn (string) u32

inline
fn (s string) u32() u32

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

#fn (string) u64

inline
fn (s string) u64() u64

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

#fn (string) parse_uint

inline
fn (s string) parse_uint(_base int, _bit_size int) !u64

parse_uint is like parse_int but for unsigned numbers

This method directly exposes the parse_uint function from strconv as a method on string. For more advanced features, consider calling strconv.common_parse_uint directly.

#fn (string) parse_int

inline
fn (s string) parse_int(_base int, _bit_size int) !i64

parse_int interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.

If the base argument is 0, the true base is implied by the string's prefix: 2 for "0b", 8 for "0" or "0o", 16 for "0x", and 10 otherwise.

Also, for argument base 0 only, underscore characters are permitted as defined by the Go syntax for integer literals.

The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64.

If bitSize is below 0 or above 64, an error is returned.

This method directly exposes the parse_int function from strconv as a method on string. For more advanced features, consider calling strconv.common_parse_int directly.

#fn (string) operator==

direct_array_access
fn (s string) == (a string) bool

#fn (string) compare

direct_array_access
fn (s string) compare(a string) int

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

#fn (string) operator<

direct_array_access
fn (s string) < (a string) bool

#fn (string) operator+

direct_array_access
fn (s string) + (a string) string

#fn (string) split_any

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

split_any splits the string to an array by any of the delim chars.

Example:

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

Split a string using the chars in the delimiter string as delimiters chars.

If the delimiter string is empty then split is used.

#fn (string) rsplit_any

direct_array_access
fn (s string) rsplit_any(delim string) []string

rsplit_any splits the string to an array by any of the delim chars in reverse order.

Example:

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

Split a string using the chars in the delimiter string as delimiters chars.

If the delimiter string is empty then rsplit is used.

#fn (string) split

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

split splits the string to an array by delim.

Example:

assert 'A B C'.split(' ') == ['A','B','C']

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

Example:

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

#fn (string) rsplit

inline
fn (s string) rsplit(delim string) []string

rsplit splits the string to an array by delim in reverse order.

Example:

assert 'A B C'.rsplit(' ') == ['C','B','A']

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

Example:

assert 'DEF'.rsplit('') == ['F','E','D']

#fn (string) split_once

fn (s string) split_once(delim string) ?(string, string)

split_once devides string into pair of string by delim.

Example:

 path, ext := 'file.ts.dts'.splice_once('.')?


assert path == 'file'
 assert ext == 'ts.dts'

Note that rsplit_once returns splitted string string as first part of pair, and returns remaining as second part of pair.

#fn (string) rsplit_once

fn (s string) rsplit_once(delim string) ?(string, string)

rsplit_once devides string into pair of string by delim.

Example:

 path, ext := 'file.ts.dts'.splice_once('.')?


assert path == 'file.ts'
 assert ext == 'dts'

Note that rsplit_once returns remaining string as first part of pair, and returns splitted string as second part of pair.

#fn (string) split_nth

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

direct_array_access
fn (s string) rsplit_nth(delim string, nth int) []string

rsplit_nth splits the string based on the passed delim substring in revese order.

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

direct_array_access
fn (s string) split_into_lines() []string

split_into_lines splits the string by newline characters.

newlines are stripped.

\r (MacOS), \n (POSIX), and \r\n (WinOS) line endings are all supported (including mixed line endings).

NOTE: algorithm is "greedy", consuming '\r\n' as a single line ending with higher priority than '\r' and '\n' as multiple endings

#fn (string) substr2

inline
fn (s string) substr2(start int, _end int, end_max bool) string

used internally for [2..4]

#fn (string) substr

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

direct_array_access
fn (s string) substr_with_check(start int, end int) !string

version of substr that is used in a[start..end] or { return an error when the index is out of range

#fn (string) substr_ni

direct_array_access
fn (s string) substr_ni(_start int, _end int) string

substr_ni returns the string between index positions start and end allowing negative indexes This function always return a valid string.

#fn (string) index_

direct_array_access
fn (s string) index_(p string) int

index returns the position of the first character of the input string.

It will return -1 if the input string can't be found.

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

direct_array_accessmanualfree
fn (s string) index_kmp(p string) int

index_kmp does KMP search.

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

direct_array_access
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

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

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

#fn (string) index_after

direct_array_access
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_u8

direct_array_access
fn (s string) index_u8(c u8) int

index_u8 returns the index of byte c if found in the string.

index_u8 returns -1 if the byte can not be found.

#fn (string) last_index_u8

direct_array_access
fn (s string) last_index_u8(c u8) 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) count

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

fn (s string) contains_u8(x u8) bool

contains_u8 returns true if the string contains the byte value x.

See also: string.index_u8 , to get the index of the byte as well.

#fn (string) contains

fn (s string) contains(substr string) bool

contains returns true if the string contains substr.

See also: string.index

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

fn (s string) contains_only(chars string) bool

contains_only returns true, if the string contains only the characters 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) starts_with

direct_array_access
fn (s string) starts_with(p string) bool

starts_with returns true if the string starts with p.

#fn (string) ends_with

direct_array_access
fn (s string) ends_with(p string) bool

ends_with returns true if the string ends with p.

#fn (string) to_lower

direct_array_access
fn (s string) to_lower() string

to_lower returns the string in all lowercase characters.

TODO only works with ASCII

#fn (string) is_lower

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

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

direct_array_access
fn (s string) is_upper() bool

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

See also: byte.is_capital

Example:

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

#fn (string) capitalize

direct_array_access
fn (s string) capitalize() string

capitalize returns the string with the first character capitalized.

Example:

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

#fn (string) is_capital

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

Example:

assert 'Hello'.is_capital() == true

Example:

assert 'HelloWorld'.is_capital() == false

#fn (string) starts_with_capital

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

Example:

assert 'Hello'.starts_with_capital() == true

Example:

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

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

inline
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

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_indexes

direct_array_access
fn (s string) trim_indexes(cutset string) (int, int)

trim_indexes gets the new start and end indicies of a string when any of the characters given in cutset were stripped from the start and end of the string. Should be used as an input to substr. If the string contains only the characters in cutset, both values returned are zero.

Example:

left, right := '-hi-'.trim_indexes('-')

#fn (string) trim_left

direct_array_access
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_right

direct_array_access
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_string_left

fn (s string) trim_string_left(str string) string

trim_string_left strips str from the start of the string.

Example:

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

#fn (string) trim_string_right

fn (s string) trim_string_right(str string) string

trim_string_right strips str from the end of the string.

Example:

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

#fn (string) trim_prefix

deprecated:use s.trim_string_left(x) insteaddeprecated_after:2022-01-19
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_suffix

deprecated:use s.trim_string_right(x) insteaddeprecated_after:2022-01-19
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) str

inline
fn (s string) str() string

str returns a copy of the string

#fn (string) at

fn (s string) at(idx int) byte

at returns the byte at index idx.

Example:

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

#fn (string) at_with_check

fn (s string) at_with_check(idx int) ?u8

version of at that is used in a[i] or { return an error when the index is out of range

#fn (&string) free

manualfreeunsafe
fn (s &string) free()

free allows for manually freeing the memory occupied by the string

#fn (string) before

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.

Example:

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

Example:

assert 'abcd'.before('.') == 'abcd'

TODO: deprecate and remove either .before or .all_before

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

Example:

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

Example:

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.

Example:

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

Example:

assert 'abcd'.all_before_last('.') == '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.

Example:

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

Example:

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.

Example:

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

Example:

assert 'abcd'.all_after_last('z') == 'abcd'

#fn (string) all_after_first

fn (s string) all_after_first(sub string) string

all_after_first returns the contents after the first occurence of sub in the string.

If the substring is not found, it returns the full input string.

Example:

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

Example:

assert 'abcd'.all_after_first('z') == 'abcd'

#fn (string) after

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

Example:

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

Example:

assert 'abcd'.after('z') == 'abcd'

TODO: deprecate either .all_after_last or .after

#fn (string) after_char

fn (s string) after_char(sub u8) 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.

Example:

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

Example:

assert 'abcd'.after_char(`:`) == 'abcd'

#fn (string) reverse

direct_array_access
fn (s string) reverse() string

reverse returns a reversed string.

Example:

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

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

fn (s string) hash() int

hash returns an integer hash of the string.

#fn (string) bytes

fn (s string) bytes() []u8

bytes returns the string converted to a byte array.

#fn (string) repeat

direct_array_access
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) 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']

Example:

assert '  sss   ssss'.fields() == ['sss', 'ssss']

#fn (string) strip_margin

inline
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 ``.

See also: string.trim_indent()

Example:

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

assert st == 'Hello there,
   this is a string,
   Everything before the first | is removed'

#fn (string) strip_margin_custom

direct_array_access
fn (s string) strip_margin_custom(del u8) string

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

#fn (string) trim_indent

fn (s string) trim_indent() string

trim_indent detects a common minimal indent of all the input lines, removes it from every line and also removes the first and the last lines if they are blank (notice difference blank vs empty).

Note that blank lines do not affect the detected indent level.

In case if there are non-blank lines with no leading whitespace characters (no indent at all) then the common indent is 0, and therefore this function doesn't change the indentation.

Example:

 st := '
      Hello there,
      this is a string,
      all the leading indents are removed
      and also the first and the last lines if they are blank
 '.trim_indent()
 

assert st == 'Hello there,
 this is a string,
 all the leading indents are removed
 and also the first and the last lines if they are blank'

#fn (string) indent_width

fn (s string) indent_width() int

indent_width returns the number of spaces or tabs at the beginning of the string.

Example:

assert '  v'.indent_width() == 2

Example:

assert '\t\tv'.indent_width() == 2

#fn (string) is_blank

fn (s string) is_blank() bool

is_blank returns true if the string is empty or contains only white-space.

Example:

assert ' '.is_blank()

Example:

assert '\t'.is_blank()

Example:

assert 'v'.is_blank() == false

#fn (string) match_glob

direct_array_access
fn (name string) match_glob(pattern string) bool

match_glob matches the string, with a Unix shell-style wildcard pattern.

Note: wildcard patterns are NOT the same as regular expressions.

They are much simpler, and do not allow backtracking, captures, etc.

The special characters used in shell-style wildcards are:

* - matches everything ? - matches any single character [seq] - matches any of the characters in the sequence [^seq] - matches any character that is NOT in the sequence Any other character in pattern, is matched 1:1 to the corresponding character in name, including / and .

You can wrap the meta-characters in brackets too, i.e. [?] matches ? in the string, and [*] matches * in the string.

Example:

assert 'ABCD'.match_glob('AB*')

Example:

assert 'ABCD'.match_glob('*D')

Example:

assert 'ABCD'.match_glob('*B*')

Example:

assert !'ABCD'.match_glob('AB')

#fn (string) is_ascii

inline
fn (s string) is_ascii() bool

is_ascii returns true if all characters belong to the US-ASCII set ([ ..~])

#fn (string) to_wide

fn (_str string) to_wide() &u16

to_wide returns a pointer to an UTF-16 version of the string receiver.

In V, strings are encoded using UTF-8 internally, but on windows most APIs, that accept strings, need them to be in UTF-16 encoding.

The returned pointer of .to_wide(), has a type of &u16, and is suitable for passing to Windows APIs that expect LPWSTR or wchar_t* parameters.

See also MultiByteToWideChar ( https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar )

#fn (string) utf32_code

fn (_rune string) utf32_code() int

Convert utf8 to utf32 the original implementation did not check for valid utf8 in the string, and could result in values greater than the utf32 spec it has been replaced by utf8_to_utf32 which has an option return type.

this function is left for backward compatibility it is used in vlib/builtin/string.v, and also in vlib/v/gen/c/cgen.v

#fn (string) runes

JavaScript
fn (s string) runes() []rune

#fn (string) slice

JavaScript
fn (s string) slice(a int, b int) string

#fn (string) substr

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

#fn (string) after

JavaScript
fn (s string) after(dot string) string

#fn (string) after_char

JavaScript
fn (s string) after_char(dot u8) string

#fn (string) all_after

JavaScript
fn (s string) all_after(dot string) string

#fn (string) all_after_last

JavaScript
fn (s string) all_after_last(dot string) string

why does this exist?

#fn (string) all_before

JavaScript
fn (s string) all_before(dot string) string

#fn (string) all_before_last

JavaScript
fn (s string) all_before_last(dot string) string

#fn (string) bool

JavaScript
fn (s string) bool() bool

#fn (string) split

JavaScript
fn (s string) split(dot string) []string

#fn (string) bytes

JavaScript
fn (s string) bytes() []u8

#fn (string) capitalize

JavaScript
fn (s string) capitalize() string

#fn (string) clone

JavaScript
fn (s string) clone() string

#fn (string) contains

JavaScript
fn (s string) contains(substr string) bool

#fn (string) contains_any

JavaScript
fn (s string) contains_any(chars string) bool

#fn (string) contains_any_substr

JavaScript
fn (s string) contains_any_substr(chars []string) bool

#fn (string) count

JavaScript
fn (s string) count(substr string) int

#fn (string) ends_with

JavaScript
fn (s string) ends_with(p string) bool

#fn (string) starts_with

JavaScript
fn (s string) starts_with(p string) bool

#fn (string) fields

JavaScript
fn (s string) fields() []string

#fn (string) find_between

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

#fn (&string) free

JavaScript
fn (s &string) free()

unnecessary in the JS backend, implemented for api parity.

#fn (string) hash

JavaScript
fn (s string) hash() int

#fn (string) int

JavaScript
fn (s string) int() int

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

#fn (string) i64

JavaScript
fn (s string) i64() i64

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

#fn (string) i8

JavaScript
fn (s string) i8() i8

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

#fn (string) i16

JavaScript
fn (s string) i16() i16

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

#fn (string) f32

JavaScript
fn (s string) f32() f32

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

#fn (string) f64

JavaScript
fn (s string) f64() f64

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

#fn (string) u16

JavaScript
fn (s string) u16() u16

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

#fn (string) u32

JavaScript
fn (s string) u32() u32

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

#fn (string) u64

JavaScript
fn (s string) u64() u64

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

#fn (string) u8

JavaScript
fn (s string) u8() u64

#fn (string) trim_right

JavaScript
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_left

JavaScriptdirect_array_access
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_string_left

JavaScript
fn (s string) trim_string_left(str string) string

trim_string_left strips str from the start of the string.

Example:

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

#fn (string) trim_string_right

JavaScript
fn (s string) trim_string_right(str string) string

trim_string_right strips str from the end of the string.

Example:

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

#fn (string) trim_prefix

JavaScriptdeprecated:use s.trim_string_left(x) insteaddeprecated_after:2022-01-19
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_suffix

JavaScriptdeprecated:use s.trim_string_right(x) insteaddeprecated_after:2022-01-19
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) at

JavaScript
fn (s string) at(idx int) u8

at returns the byte at index idx.

Example:

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

#fn (string) to_lower

JavaScript
fn (s string) to_lower() string

#fn (string) replace

JavaScript
fn (s string) replace(old_sub string, new_sub string) string

TODO: check if that behaves the same as V's own string.replace(old_sub,new_sub):

#fn (string) to_upper

JavaScript
fn (s string) to_upper() string

#fn (string) str

JavaScript
fn (s string) str() string

str returns a copy of the string

#fn (string) repeat

JavaScript
fn (s string) repeat(count int) string

#fn (string) strip_margin

JavaScript
fn (s string) strip_margin() string

TODO: Make these functions actually work.

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

JavaScriptdirect_array_access
fn (s string) strip_margin_custom(del u8) string

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

#fn (string) split_nth

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

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

JavaScript
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

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

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

#fn (string) trim_space

JavaScript
fn (s string) trim_space() string

#fn (string) index_after

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

#fn (string) split_into_lines

JavaScript
fn (s string) split_into_lines() []string

#fn (string) replace_once

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

JavaScript
fn (s string) title() string

#fn (string) index_any

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

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

JavaScript
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_capital

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

Example:

assert 'Hello'.is_capital() == true

Example:

assert 'HelloWorld'.is_capital() == false

#fn (string) starts_with_capital

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

Example:

assert 'Hello'.starts_with_capital() == true

Example:

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

#fn (string) is_upper

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

JavaScript
fn (s string) is_lower() bool

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

Example:

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

#fn (string) reverse

JavaScript
fn (s string) reverse() string

#fn (string) trim

JavaScript
fn (s string) trim(cutset string) string

#fn (string) index

JavaScript
fn (s string) index(search 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) utf32_code

JavaScript
fn (_rune string) utf32_code() int

#fn (string) compare

JavaScript
fn (s string) compare(a string) int

#fn (string) add

fn (s string) add(a string) string

#fn (string) clone

fn (a string) clone() string

#struct array

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

#fn (&array) ensure_cap

fn (mut a &array) ensure_cap(required int)

Private function. Increases the cap of an array to the required value by copying the data to a new memory location (creating a clone) unless a.cap is already large enough.

#fn (array) repeat

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 (array) repeat_to_depth

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

repeat_to_depth is an unsafe version of repeat that handles multi-dimensional arrays.

It is unsafe to call directly because depth is not checked

#fn (&array) insert

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

insert inserts a value in the array at index i and increases the index of subsequent elements by 1.

This function is type-aware and can insert items of the same or lower dimensionality as the original array. That is, if the original array is []int, then the insert val may be int or []int. If the original array is [][]int, then val may be []int or [][]int. Consider the examples.

Example:

 mut a := [1, 2, 4]
 a.insert(2, 3)          // a now is [1, 2, 3, 4]
 mut b := [3, 4]
 b.insert(0, [1, 2])     // b now is [1, 2, 3, 4]
 mut c := [[3, 4]]
 c.insert(0, [1, 2])     // c now is [[1, 2], [3, 4]]

#fn (&array) insert_many

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

insert_many is used internally to implement inserting many values into an the array beginning at i.

#fn (&array) prepend

fn (mut a &array) prepend(val voidptr)

prepend prepends one or more elements to an array.

It is shorthand for .insert(0, val)

#fn (&array) prepend_many

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

prepend_many prepends another array to this array.

NOTE: prepend is probably all you need.

NOTE: This code is never called in all of vlib

#fn (&array) delete

fn (mut a &array) delete(i int)

delete deletes array element at index i.

This is exactly the same as calling .delete_many(i, 1).

NOTE: This function does NOT operate in-place. Internally, it creates a copy of the array, skipping over the element at i, and then points the original variable to the new memory location.

Example:

 mut a := ['0', '1', '2', '3', '4', '5']
 a.delete(1) // a is now ['0', '2', '3', '4', '5']

#fn (&array) delete_many

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

delete_many deletes size elements beginning with index i NOTE: This function does NOT operate in-place. Internally, it creates a copy of the array, skipping over size elements starting at i, and then points the original variable to the new memory location.

Example:

 mut a := [1, 2, 3, 4, 5, 6, 7, 8, 9]
 b := a[..9] // creates a <code>[slice](/standard_library/builtin.html#array_slice)</code> of `a`, not a clone
 a.delete_many(4, 3) // replaces `a` with a modified clone
 dump(a) // a: [1, 2, 3, 4, 8, 9] // `a` is now different
 dump(b) // b: [1, 2, 3, 4, 5, 6, 7, 8, 9] // `b` is still the same

#fn (&array) clear

fn (mut a &array) clear()

clear clears the array without deallocating the allocated data.

It does it by setting the array length to 0

Example:

a.clear() // `a.len` is now 0

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

Example:

a.trim(3) // `a.len` is now <= 3

#fn (&array) drop

fn (mut a &array) drop(num int)

drop advances the array past the first num elements whilst preserving spare capacity.

If num is greater than len the array will be emptied.

Example:

 mut a := [1,2]
 a << 3
 a.drop(2)
 assert a == [3]
 assert a.cap > a.len

#fn (array) get_unsafe

inlineunsafe
fn (a array) get_unsafe(i int) voidptr

we manually inline this for single operations for performance without -prod

#fn (array) get

fn (a array) get(i int) voidptr

Private function. Used to implement array[] operator.

#fn (array) get_with_check

fn (a array) get_with_check(i int) voidptr

Private function. Used to implement x = a[i] or { ... }

#fn (array) first

fn (a array) first() voidptr

first returns the first element of the array.

If the array is empty, this will panic.

However, a[0] returns an error object so it can be handled with an or block.

#fn (array) last

fn (a array) last() voidptr

last returns the last element of the array.

If the array is empty, this will panic.

#fn (&array) pop

fn (mut a &array) pop() voidptr

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

If the array is empty, this will panic.

NOTE: this function reduces the length of the given array, but arrays sliced from this one will not change. They still retain their "view" of the underlying memory.

Example:

 mut a := [1, 2, 3, 4, 5, 6, 7, 8, 9]
 b := a[..9] // creates a "view" into the same memory
 c := a.pop() // c == 9
 a[1] = 5
 dump(a) // a: [1, 5, 3, 4, 5, 6, 7, 8]
 dump(b) // b: [1, 5, 3, 4, 5, 6, 7, 8, 9]

#fn (&array) delete_last

fn (mut a &array) delete_last()

delete_last efficiently deletes the last element of the array.

It does it simply by reducing the length of the array by 1.

If the array is empty, this will panic.

See also: trim

#fn (array) slice

fn (a array) slice(start int, _end int) array

slice returns an array using the same buffer as original array but starting from the start element and ending with the element before the end element of the original array with the length and capacity set to the number of the elements in the slice.

It will remain tied to the same memory location until the length increases (copy on grow) or clone is called on it.

If start and end are invalid this function will panic.

Alternative: Slices can also be made with [start..end] notation Alternative: slice_ni will always return an array.

#fn (array) slice_ni

fn (a array) slice_ni(_start int, _end int) array

slice_ni returns an array using the same buffer as original array but starting from the start element and ending with the element before the end element of the original array.

This function can use negative indexes a.slice_ni(-3, a.len) that get the last 3 elements of the array otherwise it return an empty array.

This function always return a valid array.

#fn (array) slice2

fn (a array) slice2(start int, _end int, end_max bool) array

used internally for [2..4]

#fn (array) clone_static_to_depth

fn (a array) clone_static_to_depth(depth int) array

clone_static_to_depth() returns an independent copy of a given array.

Unlike clone_to_depth it has a value receiver and is used internally for slice-clone expressions like a[2..4].clone() and in -autofree generated code.

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

inlineunsafe
fn (mut a &array) set_unsafe(i int, val voidptr)

we manually inline this for single operations for performance without -prod

#fn (&array) set

fn (mut a &array) set(i int, val voidptr)

Private function. Used to implement assignment to the array element.

#fn (&array) push

fn (mut a &array) push(val voidptr)

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

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.

Ignore the function signature. filter does not take an actual callback. Rather, it takes an it expression.

Certain array functions (filter any all) support a simplified domain-specific-language by the backend compiler to make these operations more idiomatic to V. These functions are described here, but their implementation is compiler specific.

Each function takes a boolean test expression as its single argument.

These test expressions may use it as a pointer to a single element at a time.

Example:

array.filter(it < 5) // create an array of elements less than 5

Example:

array.filter(it % 2 == 1) // create an array of only odd elements

Example:

array.filter(it.name[0] == `A`) // create an array of elements whose `name` field starts with 'A'

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

Ignore the function signature. any does not take an actual callback. Rather, it takes an it expression.

It returns true if it finds an element passing the test. Otherwise, it returns false. It doesn't modify the array.

Example:

array.any(it % 2 == 1) // will return true if any element is odd

Example:

array.any(it.name == 'Bob') // will yield `true` if any element has `.name == 'Bob'

#fn (array) all

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

all tests whether all elements in the array pass the test.

Ignore the function signature. all does not take an actual callback. Rather, it takes an it expression.

It returns false if any element fails the test. Otherwise, it returns true. It doesn't modify the array.

Example:

array.all(it % 2 == 1) // will return true if every element is odd

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

It also accepts an it expression.

Example:

 words := ['hello', 'world']
 r1 := words.map(it.to_upper())
 assert r1 == ['HELLO', 'WORLD']
 

// map can also accept anonymous functions
 r2 := words.map(fn (w string) string {
    return w.to_upper()
 })
 assert r2 == ['HELLO', 'WORLD']

#fn (&array) sort

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

sort sorts the array in place.

Ignore the function signature. Passing a callback to sort is not supported for now. Consider using the sort_with_compare method if you need it.

sort can take a boolean test expression as its single argument.

The expression uses 2 'magic' variables a and b as pointers to the two elements being compared.

Example:

array.sort() // will sort the array in ascending order

Example:

array.sort(b < a) // will sort the array in decending order

Example:

array.sort(b.name < a.name) // will sort descending by the .name field

#fn (&array) sort_with_compare

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

sort_with_compare sorts the array in-place using the results of the given function to determine sort order.

The function should return one of three values:

  • -1 when a should come before b ( a < b )

  • 1 when b should come before a ( b < a )

  • 0 when the order cannot be determined ( a == b )

Example:

 fn main() {
    mut a := ['hi', '1', '5', '3']
    a.sort_with_compare(fn (a &string, b &string) int {
        if a < b {
            return -1
        }
        if a > b {
            return 1
        }
        return 0
    })
    assert a == ['1', '3', '5', 'hi']
 }

#fn (array) contains

fn (a array) contains(value voidptr) bool

contains determines whether an array includes a certain value among its elements It will return true if the array contains an element with this value.

It is similar to any but does not take an it expression.

Example:

[1, 2, 3].contains(4) == false

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

Internally, it does this by copying the entire array to a new memory location (creating a clone).

#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 Internally, it does this by copying the entire array to a new memory location (creating a clone) unless the array.cap is already large enough.

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

#fn (&array) ensure_cap_noscan

fn (mut a &array) ensure_cap_noscan(required int)

Private function. Doubles array capacity if needed.

#fn (array) repeat_to_depth_noscan

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

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

#fn (&array) insert_noscan

fn (mut a &array) insert_noscan(i int, val voidptr)

insert inserts a value in the array at index i

#fn (&array) insert_many_noscan

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

insert_many inserts many values into the array from index i.

#fn (&array) prepend_noscan

fn (mut a &array) prepend_noscan(val voidptr)

prepend prepends one value to the array.

#fn (&array) prepend_many_noscan

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

prepend_many prepends another array to this array.

#fn (&array) pop_noscan

fn (mut a &array) pop_noscan() voidptr

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

#fn (array) clone_static_to_depth_noscan

fn (a array) clone_static_to_depth_noscan(depth int) array

clone_static_to_depth_noscan returns an independent copy of a given array.

Unlike clone_to_depth_noscan it has a value receiver and is used internally for slice-clone expressions like a[2..4].clone() and in -autofree generated code.

#fn (&array) clone_to_depth_noscan

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

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

#fn (&array) push_noscan

fn (mut a &array) push_noscan(val voidptr)

#fn (&array) push_many_noscan

unsafe
fn (mut a3 &array) push_many_noscan(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_noscan

fn (a array) reverse_noscan() array

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

#fn (&array) grow_cap_noscan

fn (mut a &array) grow_cap_noscan(amount int)

grow_cap grows the array's capacity by amount elements.

#fn (&array) grow_len_noscan

unsafe
fn (mut a &array) grow_len_noscan(amount int)

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

#fn (&array) trim

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

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

#fn (array) last

JavaScript
fn (a array) last() voidptr

last returns the last element of the array.

#fn (array) get

JavaScript
fn (a array) get(ix int) voidptr

#fn (array) repeat

JavaScript
fn (a array) repeat(count int) array

#fn (&array) set_len

JavaScript
fn (a &array) set_len(i int)

#fn (&array) sort_with_compare

JavaScript
fn (mut a &array) sort_with_compare(compare voidptr)

#fn (&array) sort_with_compare_old

JavaScript
fn (mut a &array) sort_with_compare_old(compare voidptr)

#fn (&array) sort

JavaScript
fn (mut a &array) sort()

#fn (array) index

JavaScript
fn (a array) index(v string) int

#fn (array) slice

JavaScript
fn (a array) slice(start int, end int) array

#fn (&array) insert

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

#fn (&array) insert_many

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

#fn (&array) push

JavaScript
fn (mut a &array) push(val voidptr)

#fn (&array) delete

JavaScript
fn (mut a &array) delete(i int)

delete deletes array element at index i.

#fn (&array) delete_many

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

delete_many deletes size elements beginning with index i

#fn (&array) prepend

JavaScript
fn (mut a &array) prepend(val voidptr)

prepend prepends one value to the array.

#fn (&array) prepend_many

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

prepend_many prepends another array to this array.

#fn (array) reverse

JavaScript
fn (a array) reverse() array

#fn (&array) reverse_in_place

JavaScript
fn (mut a &array) reverse_in_place()

#fn (&array) clear

JavaScript
fn (mut a &array) clear()

#fn (array) reduce

JavaScript
fn (a array) 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 (&array) pop

JavaScript
fn (mut a &array) pop() voidptr

#fn (array) first

JavaScript
fn (a array) first() voidptr

#fn (array) contains

JavaScript
fn (a array) contains(key voidptr) bool

#fn (&array) delete_last

JavaScript
fn (mut a &array) delete_last()

delete_last effectively removes last element of an array.

#fn (&array) free

JavaScriptunsafe
fn (a &array) free()

#fn (array) bytestr

JavaScript
fn (a array) bytestr() string

todo: once (a []u8) will work rewrite this

#fn (array) to_js_array

JavaScript
fn (a array) to_js_array() JS.Array

#fn (array) to_number_array

JavaScript
fn (a array) to_number_array() JS.Array

#fn (array) get

fn (a array) get(i int) voidptr

Private function. Used to implement array[] operator

#fn (&array) set

fn (mut a &array) set(i int, val voidptr)

Private function. Used to implement assignment to the array element.

#fn (array) repeat

fn (a array) repeat(nr_repeats int) array

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

#struct string

pub struct string {
pub:
	str &byte
	len int
}

#fn (string) runes

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

fn (s string) len_utf8() int

len_utf8 returns the number of runes contained in the string s.

#fn (string) clone_static

inline
fn (a string) clone_static() string

clone_static returns an independent copy of a given array.

It should be used only in -autofree generated code.

#fn (string) clone

fn (a string) clone() string

clone returns a copy of the V string a.

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

direct_array_access
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

direct_array_access
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_char

direct_array_access
fn (s string) replace_char(rep u8, with u8, repeat int) string

replace_char replaces all occurences of the character rep multiple occurences of the character passed in with with respect to repeat.

Example:

assert '\tHello!'.replace_char(`\t`,` `,8) == '        Hello!'

#fn (string) normalize_tabs

inline
fn (s string) normalize_tabs(tab_len int) string

normalize_tabs replaces all tab characters with tab_len amount of spaces

Example:

assert '\t\tpop rax\t; pop rax'.normalize_tabs(2) == '    pop rax  ; pop rax'

#fn (string) bool

inline
fn (s string) bool() bool

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

#fn (string) int

inline
fn (s string) int() int

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

#fn (string) i64

inline
fn (s string) i64() i64

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

#fn (string) i8

inline
fn (s string) i8() i8

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

#fn (string) i16

inline
fn (s string) i16() i16

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

#fn (string) f32

inline
fn (s string) f32() f32

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

#fn (string) f64

inline
fn (s string) f64() f64

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

#fn (string) u8

inline
fn (s string) u8() u8

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

#fn (string) u16

inline
fn (s string) u16() u16

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

#fn (string) u32

inline
fn (s string) u32() u32

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

#fn (string) u64

inline
fn (s string) u64() u64

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

#fn (string) parse_uint

inline
fn (s string) parse_uint(_base int, _bit_size int) !u64

parse_uint is like parse_int but for unsigned numbers

This method directly exposes the parse_uint function from strconv as a method on string. For more advanced features, consider calling strconv.common_parse_uint directly.

#fn (string) parse_int

inline
fn (s string) parse_int(_base int, _bit_size int) !i64

parse_int interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.

If the base argument is 0, the true base is implied by the string's prefix: 2 for "0b", 8 for "0" or "0o", 16 for "0x", and 10 otherwise.

Also, for argument base 0 only, underscore characters are permitted as defined by the Go syntax for integer literals.

The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64.

If bitSize is below 0 or above 64, an error is returned.

This method directly exposes the parse_int function from strconv as a method on string. For more advanced features, consider calling strconv.common_parse_int directly.

#fn (string) operator==

direct_array_access
fn (s string) == (a string) bool

#fn (string) compare

direct_array_access
fn (s string) compare(a string) int

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

#fn (string) operator<

direct_array_access
fn (s string) < (a string) bool

#fn (string) operator+

direct_array_access
fn (s string) + (a string) string

#fn (string) split_any

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

split_any splits the string to an array by any of the delim chars.

Example:

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

Split a string using the chars in the delimiter string as delimiters chars.

If the delimiter string is empty then split is used.

#fn (string) rsplit_any

direct_array_access
fn (s string) rsplit_any(delim string) []string

rsplit_any splits the string to an array by any of the delim chars in reverse order.

Example:

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

Split a string using the chars in the delimiter string as delimiters chars.

If the delimiter string is empty then rsplit is used.

#fn (string) split

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

split splits the string to an array by delim.

Example:

assert 'A B C'.split(' ') == ['A','B','C']

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

Example:

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

#fn (string) rsplit

inline
fn (s string) rsplit(delim string) []string

rsplit splits the string to an array by delim in reverse order.

Example:

assert 'A B C'.rsplit(' ') == ['C','B','A']

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

Example:

assert 'DEF'.rsplit('') == ['F','E','D']

#fn (string) split_once

fn (s string) split_once(delim string) ?(string, string)

split_once devides string into pair of string by delim.

Example:

 path, ext := 'file.ts.dts'.splice_once('.')?


assert path == 'file'
 assert ext == 'ts.dts'

Note that rsplit_once returns splitted string string as first part of pair, and returns remaining as second part of pair.

#fn (string) rsplit_once

fn (s string) rsplit_once(delim string) ?(string, string)

rsplit_once devides string into pair of string by delim.

Example:

 path, ext := 'file.ts.dts'.splice_once('.')?


assert path == 'file.ts'
 assert ext == 'dts'

Note that rsplit_once returns remaining string as first part of pair, and returns splitted string as second part of pair.

#fn (string) split_nth

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

direct_array_access
fn (s string) rsplit_nth(delim string, nth int) []string

rsplit_nth splits the string based on the passed delim substring in revese order.

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

direct_array_access
fn (s string) split_into_lines() []string

split_into_lines splits the string by newline characters.

newlines are stripped.

\r (MacOS), \n (POSIX), and \r\n (WinOS) line endings are all supported (including mixed line endings).

NOTE: algorithm is "greedy", consuming '\r\n' as a single line ending with higher priority than '\r' and '\n' as multiple endings

#fn (string) substr2

inline
fn (s string) substr2(start int, _end int, end_max bool) string

used internally for [2..4]

#fn (string) substr

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

direct_array_access
fn (s string) substr_with_check(start int, end int) !string

version of substr that is used in a[start..end] or { return an error when the index is out of range

#fn (string) substr_ni

direct_array_access
fn (s string) substr_ni(_start int, _end int) string

substr_ni returns the string between index positions start and end allowing negative indexes This function always return a valid string.

#fn (string) index_

direct_array_access
fn (s string) index_(p string) int

index returns the position of the first character of the input string.

It will return -1 if the input string can't be found.

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

direct_array_accessmanualfree
fn (s string) index_kmp(p string) int

index_kmp does KMP search.

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

direct_array_access
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

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

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

#fn (string) index_after

direct_array_access
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_u8

direct_array_access
fn (s string) index_u8(c u8) int

index_u8 returns the index of byte c if found in the string.

index_u8 returns -1 if the byte can not be found.

#fn (string) last_index_u8

direct_array_access
fn (s string) last_index_u8(c u8) 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) count

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

fn (s string) contains_u8(x u8) bool

contains_u8 returns true if the string contains the byte value x.

See also: string.index_u8 , to get the index of the byte as well.

#fn (string) contains

fn (s string) contains(substr string) bool

contains returns true if the string contains substr.

See also: string.index

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

fn (s string) contains_only(chars string) bool

contains_only returns true, if the string contains only the characters 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) starts_with

direct_array_access
fn (s string) starts_with(p string) bool

starts_with returns true if the string starts with p.

#fn (string) ends_with

direct_array_access
fn (s string) ends_with(p string) bool

ends_with returns true if the string ends with p.

#fn (string) to_lower

direct_array_access
fn (s string) to_lower() string