docs: cleanup doc comments of public APIs in builtin (found by find_doc_comments_with_no_dots.v)

This commit is contained in:
Delyan Angelov 2025-07-02 16:33:24 +03:00
parent a011888612
commit b305fa5743
20 changed files with 75 additions and 83 deletions

View file

@ -186,8 +186,8 @@ fn new_array_from_c_array_no_alloc(len int, cap int, elm_size int, c_array voidp
return arr return arr
} }
// ensure_cap increases the `cap` of an array to the required value // ensure_cap increases the `cap` of an array to the required value, if needed.
// by copying the data to a new memory location (creating a clone), // It does so by copying the data to a new memory location (creating a clone),
// unless `a.cap` is already large enough. // unless `a.cap` is already large enough.
pub fn (mut a array) ensure_cap(required int) { pub fn (mut a array) ensure_cap(required int) {
if required <= a.cap { if required <= a.cap {
@ -916,8 +916,8 @@ pub fn (mut a array) sort_with_compare(callback fn (voidptr, voidptr) int) {
} }
} }
// sorted_with_compare sorts a clone of the array, using the results of the // sorted_with_compare sorts a clone of the array. The original array is not modified.
// given function to determine sort order. The original array is not modified. // It uses the results of the given function to determine sort order.
// See also .sort_with_compare() // See also .sort_with_compare()
pub fn (a &array) sorted_with_compare(callback fn (voidptr, voidptr) int) array { pub fn (a &array) sorted_with_compare(callback fn (voidptr, voidptr) int) array {
$if freestanding { $if freestanding {
@ -930,15 +930,14 @@ pub fn (a &array) sorted_with_compare(callback fn (voidptr, voidptr) int) array
return array{} return array{}
} }
// contains determines whether an array includes a certain value among its elements // 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 will return `true` if the array contains an element with this value.
// It is similar to `.any` but does not take an `it` expression. // It is similar to `.any` but does not take an `it` expression.
// //
// Example: [1, 2, 3].contains(4) == false // Example: [1, 2, 3].contains(4) == false
pub fn (a array) contains(value voidptr) bool pub fn (a array) contains(value voidptr) bool
// index returns the first index at which a given element can be found in the array // index returns the first index at which a given element can be found in the array or `-1` if the value is not found.
// or `-1` if the value is not found.
pub fn (a array) index(value voidptr) int pub fn (a array) index(value voidptr) int
@[direct_array_access; unsafe] @[direct_array_access; unsafe]
@ -955,7 +954,7 @@ pub fn (mut a []string) free() {
// The following functions are type-specific functions that apply // The following functions are type-specific functions that apply
// to arrays of different types in different ways. // to arrays of different types in different ways.
// str returns a string representation of an array of strings // str returns a string representation of an array of strings.
// Example: ['a', 'b', 'c'].str() // => "['a', 'b', 'c']". // Example: ['a', 'b', 'c'].str() // => "['a', 'b', 'c']".
@[direct_array_access; manualfree] @[direct_array_access; manualfree]
pub fn (a []string) str() string { pub fn (a []string) str() string {

View file

@ -1,6 +1,6 @@
module builtin module builtin
// print_backtrace shows a backtrace of the current call stack on stdout // print_backtrace shows a backtrace of the current call stack on stdout.
pub fn print_backtrace() { pub fn print_backtrace() {
// At the time of backtrace_symbols_fd call, the C stack would look something like this: // At the time of backtrace_symbols_fd call, the C stack would look something like this:
// * print_backtrace_skipping_top_frames // * print_backtrace_skipping_top_frames

View file

@ -1,6 +1,6 @@
module builtin module builtin
// print_backtrace_skipping_top_frames prints the backtrace skipping N top frames // print_backtrace_skipping_top_frames prints the backtrace skipping N top frames.
pub fn print_backtrace_skipping_top_frames(xskipframes int) bool { pub fn print_backtrace_skipping_top_frames(xskipframes int) bool {
$if no_backtrace ? { $if no_backtrace ? {
return false return false

View file

@ -3,7 +3,7 @@ module builtin
// dbghelp.h is already included in cheaders.v // dbghelp.h is already included in cheaders.v
#flag windows -l dbghelp #flag windows -l dbghelp
// SymbolInfo is used by print_backtrace_skipping_top_frames_msvc // SymbolInfo is used by print_backtrace_skipping_top_frames_msvc.
pub struct SymbolInfo { pub struct SymbolInfo {
pub mut: pub mut:
f_size_of_struct u32 // must be 88 to be recognised by SymFromAddr f_size_of_struct u32 // must be 88 to be recognised by SymFromAddr
@ -61,7 +61,7 @@ const symopt_include_32bit_modules = 0x00002000
const symopt_allow_zero_address = 0x01000000 const symopt_allow_zero_address = 0x01000000
const symopt_debug = u32(0x80000000) const symopt_debug = u32(0x80000000)
// print_backtrace_skipping_top_frames prints the backtrace skipping N top frames // print_backtrace_skipping_top_frames prints the backtrace skipping N top frames.
pub fn print_backtrace_skipping_top_frames(skipframes int) bool { pub fn print_backtrace_skipping_top_frames(skipframes int) bool {
$if msvc { $if msvc {
return print_backtrace_skipping_top_frames_msvc(skipframes) return print_backtrace_skipping_top_frames_msvc(skipframes)

View file

@ -757,6 +757,7 @@ pub fn memdup_uncollectable(src voidptr, sz isize) voidptr {
} }
} }
// GCHeapUsage contains stats about the current heap usage of your program.
pub struct GCHeapUsage { pub struct GCHeapUsage {
pub: pub:
heap_size usize heap_size usize
@ -766,7 +767,7 @@ pub:
bytes_since_gc usize bytes_since_gc usize
} }
// gc_heap_usage returns the info about heap usage // gc_heap_usage returns the info about heap usage.
pub fn gc_heap_usage() GCHeapUsage { pub fn gc_heap_usage() GCHeapUsage {
$if gcboehm ? { $if gcboehm ? {
mut res := GCHeapUsage{} mut res := GCHeapUsage{}
@ -778,7 +779,7 @@ pub fn gc_heap_usage() GCHeapUsage {
} }
} }
// gc_memory_use returns the total memory use in bytes by all allocated blocks // gc_memory_use returns the total memory use in bytes by all allocated blocks.
pub fn gc_memory_use() usize { pub fn gc_memory_use() usize {
$if gcboehm ? { $if gcboehm ? {
return C.GC_get_memory_use() return C.GC_get_memory_use()

View file

@ -36,8 +36,7 @@ fn __as_cast(obj voidptr, obj_type int, expected_type int) voidptr {
return obj return obj
} }
// VAssertMetaInfo is used during assertions. An instance of it is filled in by // VAssertMetaInfo is used during assertions. An instance of it is filled in by compile time generated code, when an assertion fails.
// compile time generated code, when an assertion fails.
pub struct VAssertMetaInfo { pub struct VAssertMetaInfo {
pub: pub:
fpath string // the source file path of the assertion fpath string // the source file path of the assertion

View file

@ -178,15 +178,14 @@ pub fn gc_enable() {
C.GC_enable() C.GC_enable()
} }
// gc_disable explicitly disables the GC. Do not forget to enable it again by calling gc_enable(), // gc_disable explicitly disables the GC. Do not forget to enable it again by calling gc_enable(), when your program is otherwise idle, and can afford it.
// when your program is otherwise idle, and can afford it.
// See also gc_enable() and gc_collect(). // See also gc_enable() and gc_collect().
// Note that gc_disable() is a NOP with `-gc none`. // Note that gc_disable() is a NOP with `-gc none`.
pub fn gc_disable() { pub fn gc_disable() {
C.GC_disable() C.GC_disable()
} }
// for leak detection it is advisable to do explicit garbage collections // gc_check_leaks is useful for leak detection (it does an explicit garbage collections, but only when a program is compiled with `-gc boehm_leak`).
pub fn gc_check_leaks() { pub fn gc_check_leaks() {
$if gcboehm_leak ? { $if gcboehm_leak ? {
C.GC_gcollect() C.GC_gcollect()
@ -220,18 +219,19 @@ fn C.GC_remove_roots(voidptr, voidptr)
fn C.GC_get_sp_corrector() fn (voidptr, voidptr) fn C.GC_get_sp_corrector() fn (voidptr, voidptr)
fn C.GC_set_sp_corrector(fn (voidptr, voidptr)) fn C.GC_set_sp_corrector(fn (voidptr, voidptr))
// GC warnings are silenced by default, but can be redirected to a custom cb function by programs too: // FnGC_WarnCB is the type of the callback, that you have to define, if you want to redirect GC warnings and handle them.
// Note: GC warnings are silenced by default. Use gc_set_warn_proc/1 to set your own handler for them.
pub type FnGC_WarnCB = fn (msg &char, arg usize) pub type FnGC_WarnCB = fn (msg &char, arg usize)
fn C.GC_get_warn_proc() FnGC_WarnCB fn C.GC_get_warn_proc() FnGC_WarnCB
fn C.GC_set_warn_proc(cb FnGC_WarnCB) fn C.GC_set_warn_proc(cb FnGC_WarnCB)
// gc_get_warn_proc returns the current callback fn, that will be used for printing GC warnings // gc_get_warn_proc returns the current callback fn, that will be used for printing GC warnings.
pub fn gc_get_warn_proc() FnGC_WarnCB { pub fn gc_get_warn_proc() FnGC_WarnCB {
return C.GC_get_warn_proc() return C.GC_get_warn_proc()
} }
// gc_set_warn_proc sets the callback fn, that will be used for printing GC warnings // gc_set_warn_proc sets the callback fn, that will be used for printing GC warnings.
pub fn gc_set_warn_proc(cb FnGC_WarnCB) { pub fn gc_set_warn_proc(cb FnGC_WarnCB) {
C.GC_set_warn_proc(cb) C.GC_set_warn_proc(cb)
} }

View file

@ -39,8 +39,8 @@ pub fn gc_is_enabled() bool {
// Note that gc_enable() is a NOP with `-gc none`. // Note that gc_enable() is a NOP with `-gc none`.
pub fn gc_enable() {} pub fn gc_enable() {}
// gc_disable explicitly disables the GC. Do not forget to enable it again by calling gc_enable(), // gc_disable explicitly disables the GC.
// when your program is otherwise idle, and can afford it. // Do not forget to enable it again by calling gc_enable(), when your program is otherwise idle, and can afford it.
// See also gc_enable() and gc_collect(). // See also gc_enable() and gc_collect().
// Note that gc_disable() is a NOP with `-gc none`. // Note that gc_disable() is a NOP with `-gc none`.
pub fn gc_disable() {} pub fn gc_disable() {}

View file

@ -9,23 +9,23 @@ pub struct VContext {
pub type byte = u8 pub type byte = u8
// ptr_str returns the address of `ptr` as a `string`. // ptr_str returns a string with the address of `ptr`.
pub fn ptr_str(ptr voidptr) string { pub fn ptr_str(ptr voidptr) string {
buf1 := u64(ptr).hex() buf1 := u64(ptr).hex()
return buf1 return buf1
} }
// str returns string equivalent of x // str returns the string equivalent of x.
pub fn (x isize) str() string { pub fn (x isize) str() string {
return i64(x).str() return i64(x).str()
} }
// str returns string equivalent of x // str returns the string equivalent of x.
pub fn (x usize) str() string { pub fn (x usize) str() string {
return u64(x).str() return u64(x).str()
} }
// str returns string equivalent of cptr // str returns a string with the address stored in the pointer cptr.
pub fn (cptr &char) str() string { pub fn (cptr &char) str() string {
return u64(cptr).hex() return u64(cptr).hex()
} }
@ -63,10 +63,10 @@ pub const max_u32 = u32(4294967295)
pub const min_u64 = u64(0) pub const min_u64 = u64(0)
pub const max_u64 = u64(18446744073709551615) pub const max_u64 = u64(18446744073709551615)
// This implementation is the quickest with gcc -O2
// str_l returns the string representation of the integer nn with max chars. // str_l returns the string representation of the integer nn with max chars.
@[direct_array_access; inline] @[direct_array_access; inline]
fn (nn int) str_l(max int) string { fn (nn int) str_l(max int) string {
// This implementation is the quickest with gcc -O2
unsafe { unsafe {
mut n := i64(nn) mut n := i64(nn)
mut d := 0 mut d := 0
@ -554,10 +554,9 @@ pub fn (b []u8) bytestr() string {
} }
} }
// byterune attempts to decode a sequence of bytes // byterune attempts to decode a sequence of bytes, from utf8 to utf32.
// from utf8 to utf32 and return the result as a rune // It return the result as a rune.
// it will produce an error if there are more than // It will produce an error, if there are more than four bytes in the array.
// four bytes in the array.
pub fn (b []u8) byterune() !rune { pub fn (b []u8) byterune() !rune {
r := b.utf8_to_utf32()! r := b.utf8_to_utf32()!
return rune(r) return rune(r)

View file

@ -67,8 +67,7 @@ fn v_sort(mut arr array, comparator fn (voidptr, voidptr) int) {
} }
} }
// trim trims the array length to "index" without modifying the allocated data. If "index" is greater // trim trims the array length to "index" without modifying the allocated data. If "index" is greater than len nothing will be changed.
// than len nothing will be changed.
pub fn (mut a array) trim(index int) { pub fn (mut a array) trim(index int) {
if index < a.len { if index < a.len {
a.len = index a.len = index
@ -285,7 +284,7 @@ fn arr_copy(mut dst array, src array, count int) {
} }
} }
// delete_many deletes `size` elements beginning with index `i` // delete_many deletes `size` elements beginning with index `i`.
pub fn (mut a array) delete_many(i int, size int) { pub fn (mut a array) delete_many(i int, size int) {
#a.val.arr.make_copy() #a.val.arr.make_copy()
#a.val.arr.arr.splice(i.valueOf(),size.valueOf()) #a.val.arr.arr.splice(i.valueOf(),size.valueOf())
@ -320,8 +319,7 @@ pub fn (mut a array) clear() {
#a.val.arr.arr.length = 0 #a.val.arr.arr.length = 0
} }
// reduce executes a given reducer function on each element of the array, // reduce executes a given reducer function on each element of the array, resulting in a single output value.
// resulting in a single output value.
pub fn (a array) reduce(iter fn (int, int) int, accum_start int) int { pub fn (a array) reduce(iter fn (int, int) int, accum_start int) int {
mut accum_ := accum_start mut accum_ := accum_start
/*#for (let i = 0;i < a.arr.length;i++) { /*#for (let i = 0;i < a.arr.length;i++) {

View file

@ -22,13 +22,13 @@ pub fn panic_n(s string, n i64) {
exit(1) exit(1)
} }
// IError holds information about an error instance // IError holds information about an error instance.
pub interface IError { pub interface IError {
msg() string msg() string
code() int code() int
} }
// str returns the message of IError // str returns the message of IError.
pub fn (err IError) str() string { pub fn (err IError) str() string {
return match err { return match err {
None__ { None__ {
@ -49,34 +49,34 @@ pub fn (err IError) str() string {
// Error is the empty default implementation of `IError`. // Error is the empty default implementation of `IError`.
pub struct Error {} pub struct Error {}
// msg returns the message of Error // msg returns the message of Error.
pub fn (err Error) msg() string { pub fn (err Error) msg() string {
return '' return ''
} }
// code returns the code of Error // code returns the code of Error.
pub fn (err Error) code() int { pub fn (err Error) code() int {
return 0 return 0
} }
// MessageError is the default implementation of the `IError` interface that is returned by the `error()` function // MessageError is the default implementation of the `IError` interface that is returned by the `error()` function.
struct MessageError { struct MessageError {
pub: pub:
msg string msg string
code int code int
} }
// str returns the message and code of the MessageError // str returns the message and code of the MessageError.
pub fn (err MessageError) str() string { pub fn (err MessageError) str() string {
return err.msg return err.msg
} }
// msg returns the message of the MessageError // msg returns the message of the MessageError.
pub fn (err MessageError) msg() string { pub fn (err MessageError) msg() string {
return err.msg return err.msg
} }
// code returns the code of MessageError // code returns the code of MessageError.
pub fn (err MessageError) code() int { pub fn (err MessageError) code() int {
return err.code return err.code
} }
@ -96,7 +96,7 @@ pub struct Option {
err IError = none__ err IError = none__
} }
// str returns the Option type: ok, none, or error // str returns the Option type: ok, none, or error.
pub fn (o Option) str() string { pub fn (o Option) str() string {
if o.state == 0 { if o.state == 0 {
return 'Option{ ok }' return 'Option{ ok }'
@ -112,7 +112,7 @@ pub struct _option {
err IError = none__ err IError = none__
} }
// str returns the Option type: ok, none, or error // str returns the Option type: ok, none, or error.
pub fn (o _option) str() string { pub fn (o _option) str() string {
if o.state == 0 { if o.state == 0 {
return 'Option{ ok }' return 'Option{ ok }'
@ -123,7 +123,7 @@ pub fn (o _option) str() string {
return 'Option{ error: "${o.err}" }' return 'Option{ error: "${o.err}" }'
} }
// trace_error prints to stderr a string and a backtrace of the error // trace_error prints to stderr a string and a backtrace of the error.
fn trace_error(x string) { fn trace_error(x string) {
eprintln('> ${@FN} | ${x}') eprintln('> ${@FN} | ${x}')
} }

View file

@ -176,8 +176,7 @@ pub fn (x u8) hex() string {
return res return res
} }
// hex returns a string with the hexadecimal representation // hex returns a string with the hexadecimal representation of the byte elements of the array.
// of the byte elements of the array.
pub fn (b []u8) hex() string { pub fn (b []u8) hex() string {
mut hex := '' mut hex := ''
for i in b { for i in b {

View file

@ -12,8 +12,7 @@ pub fn JS.Promise.reject(JS.Any) JS.Promise
pub fn JS.Promise.resolve(JS.Any) JS.Promise pub fn JS.Promise.resolve(JS.Any) JS.Promise
pub fn JS.Promise.race(JS.Array) JS.Promise pub fn JS.Promise.race(JS.Array) JS.Promise
// The Promise object represents the eventual completion (or failure) // Promise represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
// of an asynchronous operation and its resulting value.
pub struct Promise[T] { pub struct Promise[T] {
mut: mut:
promise JS.Promise @[noinit] promise JS.Promise @[noinit]
@ -28,7 +27,7 @@ pub fn (p Promise[T]) then(on_fulfilled fn (T), on_rejected fn (JS.Any)) {
p.promise.then(on_fulfilled, on_rejected) p.promise.then(on_fulfilled, on_rejected)
} }
// catch method returns a Promise and deals with rejected cases only. // catch returns a Promise and deals with rejected cases only.
pub fn (p Promise[T]) catch(callback fn (error JS.Any)) Promise[T] { pub fn (p Promise[T]) catch(callback fn (error JS.Any)) Promise[T] {
promise := p.promise.catch(callback) promise := p.promise.catch(callback)
return Promise[T]{promise} return Promise[T]{promise}
@ -39,20 +38,20 @@ pub fn (p Promise[T]) finally[U](callback fn ()) Promise[JS.Any] {
return Promise[JS.Any]{promise} return Promise[JS.Any]{promise}
} }
// reject<E> returns promise which was rejected because of specified error // promise_reject returns promise which was rejected because of specified error.
pub fn promise_reject(error JS.Any) Promise[JS.Any] { pub fn promise_reject(error JS.Any) Promise[JS.Any] {
promise := JS.Promise.reject(error) promise := JS.Promise.reject(error)
return Promise[JS.Any]{promise} return Promise[JS.Any]{promise}
} }
// resolve<E> returns promise which was resolved with specified value // resolve returns promise which was resolved with specified value.
pub fn promise_resolve[T](result T) Promise[T] { pub fn promise_resolve[T](result T) Promise[T] {
promise := JS.Promise.resolve(result) promise := JS.Promise.resolve(result)
return Promise[T]{promise} return Promise[T]{promise}
} }
// race returns returns a promise that fulfills or rejects as soon as one of // promise_race returns a promise, that fulfills or rejects, as soon as one of the promises in an iterable fulfills or rejects.
// the promises in an iterable fulfills or rejects, with the value or reason from that promise. // It returns the value or reason from that first promise.
pub fn promise_race[T](promises []Promise[T]) Promise[T] { pub fn promise_race[T](promises []Promise[T]) Promise[T] {
promises_ := JS.Array.prototype.constructor() promises_ := JS.Array.prototype.constructor()
@ -70,8 +69,7 @@ pub fn JS.Promise.allSettled(JS.Array) JS.Promise
/* /*
pub type JsAny = JS.Any pub type JsAny = JS.Any
// all takes an iterable of promises as an input, and returns a single Promise that resolves to an array of // all takes an iterable of promises as an input, and returns a single Promise that resolves to an array of the results of the input promises.
// the results of the input promises
pub fn all(array []JS.Promise) Promise<JS.Array, js.promise.JsAny> { pub fn all(array []JS.Promise) Promise<JS.Array, js.promise.JsAny> {
mut promise := JS.Promise(JS.Any(voidptr(0))) mut promise := JS.Promise(JS.Any(voidptr(0)))
#promise = Promise.all(array.arr.arr); #promise = Promise.all(array.arr.arr);

View file

@ -480,7 +480,7 @@ pub fn (mut s []string) sort_by_len() {
s.sort_with_compare(compare_strings_by_len) s.sort_with_compare(compare_strings_by_len)
} }
// str returns a copy of the string // str returns a copy of the string.
pub fn (s string) str() string { pub fn (s string) str() string {
return s.clone() return s.clone()
} }

View file

@ -457,7 +457,7 @@ fn (mut m map) expand() {
} }
} }
// A rehash is the reconstruction of the hash table: // rehash reconstructs the hash table.
// All the elements in the container are rearranged according // All the elements in the container are rearranged according
// to their hash value into the newly sized key-value container. // to their hash value into the newly sized key-value container.
// Rehashes are performed when the load_factor is going to surpass // Rehashes are performed when the load_factor is going to surpass
@ -467,7 +467,7 @@ fn (mut m map) rehash() {
m.reserve(meta_bytes) m.reserve(meta_bytes)
} }
// reserve memory for the map meta data // reserve memory for the map meta data.
pub fn (mut m map) reserve(meta_bytes u32) { pub fn (mut m map) reserve(meta_bytes u32) {
unsafe { unsafe {
// TODO: use realloc_data here too // TODO: use realloc_data here too
@ -486,7 +486,7 @@ pub fn (mut m map) reserve(meta_bytes u32) {
} }
} }
// This method works like rehash. However, instead of rehashing the // cached_rehashd works like rehash. However, instead of rehashing the
// key completely, it uses the bits cached in `metas`. // key completely, it uses the bits cached in `metas`.
fn (mut m map) cached_rehash(old_cap u32) { fn (mut m map) cached_rehash(old_cap u32) {
old_metas := m.metas old_metas := m.metas
@ -509,7 +509,7 @@ fn (mut m map) cached_rehash(old_cap u32) {
unsafe { free(old_metas) } unsafe { free(old_metas) }
} }
// This method is used for assignment operators. If the argument-key // get_and_set 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. // 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. // If the key exists, its respective value is returned.
fn (mut m map) get_and_set(key voidptr, zero voidptr) voidptr { fn (mut m map) get_and_set(key voidptr, zero voidptr) voidptr {

View file

@ -3,7 +3,7 @@
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module builtin module builtin
// IError holds information about an error instance // IError holds information about an error instance.
pub interface IError { pub interface IError {
msg() string msg() string
code() int code() int
@ -26,7 +26,7 @@ fn _result_ok(data voidptr, mut res _result, size int) {
} }
} }
// str returns the message of IError // str returns the message of IError.
pub fn (err IError) str() string { pub fn (err IError) str() string {
return match err { return match err {
None__ { None__ {
@ -55,14 +55,14 @@ pub fn (err Error) code() int {
return 0 return 0
} }
// MessageError is the default implementation of the `IError` interface that is returned by the `error()` function // MessageError is the default implementation of the `IError` interface that is returned by the `error()` function.
struct MessageError { struct MessageError {
pub: pub:
msg string msg string
code int code int
} }
// str returns both the .msg and .code of MessageError, when .code is != 0 // str returns both the .msg and .code of MessageError, when .code is != 0 .
pub fn (err MessageError) str() string { pub fn (err MessageError) str() string {
if err.code > 0 { if err.code > 0 {
return '${err.msg}; code: ${err.code}' return '${err.msg}; code: ${err.code}'
@ -70,12 +70,12 @@ pub fn (err MessageError) str() string {
return err.msg return err.msg
} }
// msg returns only the message of MessageError // msg returns only the message of MessageError.
pub fn (err MessageError) msg() string { pub fn (err MessageError) msg() string {
return err.msg return err.msg
} }
// code returns only the code of MessageError // code returns only the code of MessageError.
pub fn (err MessageError) code() int { pub fn (err MessageError) code() int {
return err.code return err.code
} }

View file

@ -9,7 +9,7 @@ import strings
// updated. if you uncomment it you will see the issue // updated. if you uncomment it you will see the issue
// type rune = int // type rune = int
// str converts a rune to string // str converts a rune to string.
pub fn (c rune) str() string { pub fn (c rune) str() string {
return utf32_to_str(u32(c)) return utf32_to_str(u32(c))
/* /*
@ -31,7 +31,7 @@ pub fn (c rune) str() string {
*/ */
} }
// string converts a rune array to a string // string converts a rune array to a string.
@[manualfree] @[manualfree]
pub fn (ra []rune) string() string { pub fn (ra []rune) string() string {
mut sb := strings.new_builder(ra.len) mut sb := strings.new_builder(ra.len)
@ -53,7 +53,7 @@ pub fn (c rune) repeat(count int) string {
return res.repeat(count) return res.repeat(count)
} }
// bytes converts a rune to an array of bytes // bytes converts a rune to an array of bytes.
@[manualfree] @[manualfree]
pub fn (c rune) bytes() []u8 { pub fn (c rune) bytes() []u8 {
mut res := []u8{cap: 5} mut res := []u8{cap: 5}

View file

@ -593,14 +593,14 @@ pub fn (s string) replace_char(rep u8, with u8, repeat int) string {
} }
} }
// normalize_tabs replaces all tab characters with `tab_len` amount of spaces // 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' // Example: assert '\t\tpop rax\t; pop rax'.normalize_tabs(2) == ' pop rax ; pop rax'
@[inline] @[inline]
pub fn (s string) normalize_tabs(tab_len int) string { pub fn (s string) normalize_tabs(tab_len int) string {
return s.replace_char(`\t`, ` `, tab_len) return s.replace_char(`\t`, ` `, tab_len)
} }
// expand_tabs replaces tab characters (\t) in the input string with spaces to achieve proper column alignment // expand_tabs replaces tab characters (\t) in the input string with spaces to achieve proper column alignment .
// Example: assert 'AB\tHello!'.expand_tabs(4) == 'AB Hello!' // Example: assert 'AB\tHello!'.expand_tabs(4) == 'AB Hello!'
pub fn (s string) expand_tabs(tab_len int) string { pub fn (s string) expand_tabs(tab_len int) string {
if tab_len <= 0 { if tab_len <= 0 {
@ -2503,7 +2503,7 @@ pub fn (s string) repeat(count int) string {
return unsafe { ret.vstring_with_len(new_len) } return unsafe { ret.vstring_with_len(new_len) }
} }
// fields returns a string array of the string split by `\t` and ` ` // fields returns a string array of the string split by `\t` and ` ` .
// Example: assert '\t\tv = v'.fields() == ['v', '=', 'v'] // Example: assert '\t\tv = v'.fields() == ['v', '=', 'v']
// Example: assert ' sss ssss'.fields() == ['sss', 'ssss'] // Example: assert ' sss ssss'.fields() == ['sss', 'ssss']
pub fn (s string) fields() []string { pub fn (s string) fields() []string {
@ -2954,7 +2954,7 @@ pub:
end string = '\n' end string = '\n'
} }
// wrap wraps the string `s` when each line exceeds the width specified in `width` // wrap wraps the string `s` when each line exceeds the width specified in `width` .
// (default value is 80), and will use `end` (default value is '\n') as a line break. // (default value is 80), and will use `end` (default value is '\n') as a line break.
// Example: `assert 'Hello, my name is Carl and I am a delivery'.wrap(width: 20) == 'Hello, my name is\nCarl and I am a\ndelivery'` // Example: `assert 'Hello, my name is Carl and I am a delivery'.wrap(width: 20) == 'Hello, my name is\nCarl and I am a\ndelivery'`
pub fn (s string) wrap(config WrapConfig) string { pub fn (s string) wrap(config WrapConfig) string {
@ -2983,7 +2983,7 @@ pub fn (s string) wrap(config WrapConfig) string {
return sb.str() return sb.str()
} }
// hex returns a string with the hexadecimal representation of the bytes of the string `s` // hex returns a string with the hexadecimal representation of the bytes of the string `s` .
pub fn (s string) hex() string { pub fn (s string) hex() string {
if s == '' { if s == '' {
return '' return ''
@ -3024,7 +3024,7 @@ pub fn (s string) runes_iterator() RunesIterator {
} }
} }
// next is the method that will be called for each iteration in `for r in s.runes_iterator() {` // next is the method that will be called for each iteration in `for r in s.runes_iterator() {` .
pub fn (mut ri RunesIterator) next() ?rune { pub fn (mut ri RunesIterator) next() ?rune {
for ri.i >= ri.s.len { for ri.i >= ri.s.len {
return none return none

View file

@ -92,8 +92,7 @@ pub fn string_from_wide2(_wstr &u16, len int) string {
} }
} }
// wide_to_ansi create an ANSI string, given a windows // wide_to_ansi create an ANSI string, given a windows style string, encoded in UTF-16.
// style string, encoded in UTF-16.
// It use CP_ACP, which is ANSI code page identifier, as dest encoding. // It use CP_ACP, which is ANSI code page identifier, as dest encoding.
// NOTE: It return a vstring(encoded in UTF-8) []u8 under Linux. // NOTE: It return a vstring(encoded in UTF-8) []u8 under Linux.
pub fn wide_to_ansi(_wstr &u16) []u8 { pub fn wide_to_ansi(_wstr &u16) []u8 {

View file

@ -3,7 +3,7 @@
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module builtin module builtin
// utf8_char_len returns the length in bytes of a UTF-8 encoded codepoint that starts with the byte `b` // utf8_char_len returns the length in bytes of a UTF-8 encoded codepoint that starts with the byte `b`.
pub fn utf8_char_len(b u8) int { pub fn utf8_char_len(b u8) int {
return ((0xe5000000 >> ((b >> 3) & 0x1e)) & 3) + 1 return ((0xe5000000 >> ((b >> 3) & 0x1e)) & 3) + 1
} }