Skip to content

Commit

Permalink
vlib: update doc comments (#19231)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Aug 30, 2023
1 parent 78c3432 commit f755118
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 20 deletions.
8 changes: 4 additions & 4 deletions vlib/arrays/arrays.v
Expand Up @@ -679,8 +679,8 @@ pub fn carray_to_varray[T](c_array_data voidptr, items int) []T {
return v_array
}

// find_first returns the first element that matches the given predicate
// returns `none`, if there is no match found
// find_first returns the first element that matches the given predicate.
// Returns `none` if no match is found.
// Example: arrays.find_first([1, 2, 3, 4, 5], fn (i int) bool { return i == 3 })? // => 3
pub fn find_first[T](array []T, predicate fn (elem T) bool) ?T {
if array.len == 0 {
Expand All @@ -694,8 +694,8 @@ pub fn find_first[T](array []T, predicate fn (elem T) bool) ?T {
return none
}

// find_last returns the last element that matches the given predicate
// returns `none`, if there is no match found
// find_last returns the last element that matches the given predicate.
// Returns `none` if no match is found.
// Example: arrays.find_last([1, 2, 3, 4, 5], fn (i int) bool { return i == 3})? // => 3
pub fn find_last[T](array []T, predicate fn (elem T) bool) ?T {
if array.len == 0 {
Expand Down
6 changes: 3 additions & 3 deletions vlib/builtin/map.v
Expand Up @@ -578,7 +578,7 @@ fn (mut d DenseArray) delete(i int) {
}
}

// Removes the mapping of a particular key from the map.
// delete removes the mapping of a particular key from the map.
[unsafe]
pub fn (mut m map) delete(key voidptr) {
mut index, mut meta := m.key_to_index(key)
Expand Down Expand Up @@ -618,7 +618,7 @@ pub fn (mut m map) delete(key voidptr) {
}
}

// Returns all keys in the map.
// keys returns all keys in the map.
pub fn (m &map) keys() array {
mut keys := __new_array(m.len, 0, m.key_bytes)
mut item := unsafe { &u8(keys.data) }
Expand All @@ -645,7 +645,7 @@ pub fn (m &map) keys() array {
return keys
}

// Returns all values in the map.
// values returns all values in the map.
pub fn (m &map) values() array {
mut values := __new_array(m.len, 0, m.value_bytes)
mut item := unsafe { &u8(values.data) }
Expand Down
3 changes: 1 addition & 2 deletions vlib/dl/dl.v
Expand Up @@ -26,8 +26,7 @@ pub fn get_libname(libname string) string {
return '${libname}${dl.dl_ext}'
}

// open_opt - loads the dynamic shared object.
// Unlike open, open_opt return an option.
// open_opt tries to load a given dynamic shared object.
pub fn open_opt(filename string, flags int) !voidptr {
shared_object_handle := open(filename, flags)
if shared_object_handle == 0 {
Expand Down
2 changes: 1 addition & 1 deletion vlib/dl/dl_nix.c.v
Expand Up @@ -23,7 +23,7 @@ fn C.dlclose(handle voidptr) int

fn C.dlerror() &char

// open loads the dynamic shared object.
// open loads a given dynamic shared object.
pub fn open(filename string, flags int) voidptr {
return C.dlopen(&char(filename.str), flags)
}
Expand Down
2 changes: 1 addition & 1 deletion vlib/net/http/cookie.v
Expand Up @@ -105,7 +105,7 @@ pub fn read_cookies(h map[string][]string, filter string) []&Cookie {
return cookies
}

// Returns the serialization of the cookie for use in a Cookie header
// str returns the serialization of the cookie for use in a Cookie header
// (if only Name and Value are set) or a Set-Cookie response
// header (if other fields are set).
//
Expand Down
2 changes: 1 addition & 1 deletion vlib/net/http/request.v
Expand Up @@ -444,7 +444,7 @@ pub fn parse_multipart_form(body string, boundary string) (map[string]string, ma
return form, files
}

// parse_disposition parses the Content-Disposition header of a multipart form
// parse_disposition parses the Content-Disposition header of a multipart form.
// Returns a map of the key="value" pairs
// Example: assert parse_disposition('Content-Disposition: form-data; name="a"; filename="b"') == {'name': 'a', 'filename': 'b'}
fn parse_disposition(line string) map[string]string {
Expand Down
4 changes: 2 additions & 2 deletions vlib/os/environment.c.v
Expand Up @@ -16,8 +16,8 @@ pub fn getenv(key string) string {
return getenv_opt(key) or { '' }
}

// `getenv_opt` returns the value of the environment variable named by the key
// If there is not one found, it returns `none`.
// `getenv_opt` returns the value of a given environment variable.
// Returns `none` if the environment variable does not exist.
[manualfree]
pub fn getenv_opt(key string) ?string {
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions vlib/os/environment.js.v
Expand Up @@ -21,8 +21,8 @@ pub fn getenv(key string) string {
return res
}

// `getenv_opt` returns the value of the environment variable named by the key.
// If such an environment variable does not exist, then it returns `none`.
// `getenv_opt` returns the value of a given environment variable.
// Returns `none` if the environment variable does not exist.
pub fn getenv_opt(key string) ?string {
#if (!$ENV[key]) return none__;

Expand Down
4 changes: 2 additions & 2 deletions vlib/os/file.c.v
Expand Up @@ -51,7 +51,7 @@ fn fix_windows_path(path string) string {
return p
}

// open_file can be used to open or create a file with custom flags and permissions and returns a `File` object.
// open_file tries to open or create a file with custom flags and permissions.
pub fn open_file(path string, mode string, options ...int) !File {
mut flags := 0
mut seek_to_end := false
Expand Down Expand Up @@ -129,7 +129,7 @@ pub fn open_file(path string, mode string, options ...int) !File {
}
}

// open tries to open a file for reading and returns back a read-only `File` object.
// open tries to open a file from a given path for reading.
pub fn open(path string) !File {
/*
$if linux {
Expand Down
1 change: 1 addition & 0 deletions vlib/os/open_uri_default.c.v
@@ -1,5 +1,6 @@
module os

// open_uri opens a given uri.
pub fn open_uri(uri string) ! {
mut vopen_uri_cmd := getenv('VOPEN_URI_CMD')
if vopen_uri_cmd == '' {
Expand Down
1 change: 1 addition & 0 deletions vlib/os/open_uri_windows.c.v
Expand Up @@ -4,6 +4,7 @@ import dl

type ShellExecuteWin = fn (voidptr, &u16, &u16, &u16, &u16, int)

// open_uri opens a given uri.
pub fn open_uri(uri string) ! {
mut vopen_uri_cmd := getenv('VOPEN_URI_CMD')
if vopen_uri_cmd != '' {
Expand Down
3 changes: 2 additions & 1 deletion vlib/os/os.c.v
Expand Up @@ -1001,7 +1001,8 @@ pub fn chown(path string, owner int, group int) ! {
}
}

// open_append opens `path` file for appending.
// open_append tries to open a file from a given path.
// If successfull, it and returns a `File` for appending.
pub fn open_append(path string) !File {
mut file := File{}
$if windows {
Expand Down
2 changes: 1 addition & 1 deletion vlib/os/os.v
Expand Up @@ -288,7 +288,7 @@ pub fn input_opt(prompt string) ?string {
}

// input returns a one-line string from stdin, after printing a prompt.
// In the event of error (end of input), it returns '<EOF>'.
// Returns '<EOF>' in case of an error (end of input).
pub fn input(prompt string) string {
res := input_opt(prompt) or { return '<EOF>' }
return res
Expand Down

0 comments on commit f755118

Please sign in to comment.