mirror of
https://github.com/vlang/v.git
synced 2025-08-03 09:47:15 -04:00
docs: cleanup doc comments of public APIs in builtin
(found by find_doc_comments_with_no_dots.v)
This commit is contained in:
parent
a011888612
commit
b305fa5743
@ -186,8 +186,8 @@ fn new_array_from_c_array_no_alloc(len int, cap int, elm_size int, c_array voidp
|
||||
return arr
|
||||
}
|
||||
|
||||
// ensure_cap increases the `cap` of an array to the required value
|
||||
// by copying the data to a new memory location (creating a clone),
|
||||
// ensure_cap increases the `cap` of an array to the required value, if needed.
|
||||
// It does so by copying the data to a new memory location (creating a clone),
|
||||
// unless `a.cap` is already large enough.
|
||||
pub fn (mut a array) ensure_cap(required int) {
|
||||
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
|
||||
// given function to determine sort order. The original array is not modified.
|
||||
// sorted_with_compare sorts a clone of the array. The original array is not modified.
|
||||
// It uses the results of the given function to determine sort order.
|
||||
// See also .sort_with_compare()
|
||||
pub fn (a &array) sorted_with_compare(callback fn (voidptr, voidptr) int) array {
|
||||
$if freestanding {
|
||||
@ -930,15 +930,14 @@ pub fn (a &array) sorted_with_compare(callback fn (voidptr, voidptr) int) 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 is similar to `.any` but does not take an `it` expression.
|
||||
//
|
||||
// Example: [1, 2, 3].contains(4) == false
|
||||
pub fn (a array) contains(value voidptr) bool
|
||||
|
||||
// index returns the first index at which a given element can be found in the array
|
||||
// or `-1` if the value is not found.
|
||||
// index returns the first index at which a given element can be found in the array or `-1` if the value is not found.
|
||||
pub fn (a array) index(value voidptr) int
|
||||
|
||||
@[direct_array_access; unsafe]
|
||||
@ -955,7 +954,7 @@ pub fn (mut a []string) free() {
|
||||
// The following functions are type-specific functions that apply
|
||||
// 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']".
|
||||
@[direct_array_access; manualfree]
|
||||
pub fn (a []string) str() string {
|
||||
|
@ -1,6 +1,6 @@
|
||||
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() {
|
||||
// At the time of backtrace_symbols_fd call, the C stack would look something like this:
|
||||
// * print_backtrace_skipping_top_frames
|
||||
|
@ -1,6 +1,6 @@
|
||||
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 {
|
||||
$if no_backtrace ? {
|
||||
return false
|
||||
|
@ -3,7 +3,7 @@ module builtin
|
||||
// dbghelp.h is already included in cheaders.v
|
||||
#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 mut:
|
||||
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_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 {
|
||||
$if msvc {
|
||||
return print_backtrace_skipping_top_frames_msvc(skipframes)
|
||||
|
@ -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:
|
||||
heap_size usize
|
||||
@ -766,7 +767,7 @@ pub:
|
||||
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 {
|
||||
$if gcboehm ? {
|
||||
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 {
|
||||
$if gcboehm ? {
|
||||
return C.GC_get_memory_use()
|
||||
|
@ -36,8 +36,7 @@ fn __as_cast(obj voidptr, obj_type int, expected_type int) voidptr {
|
||||
return obj
|
||||
}
|
||||
|
||||
// VAssertMetaInfo is used during assertions. An instance of it is filled in by
|
||||
// compile time generated code, when an assertion fails.
|
||||
// VAssertMetaInfo is used during assertions. An instance of it is filled in by compile time generated code, when an assertion fails.
|
||||
pub struct VAssertMetaInfo {
|
||||
pub:
|
||||
fpath string // the source file path of the assertion
|
||||
|
@ -178,15 +178,14 @@ pub fn gc_enable() {
|
||||
C.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.
|
||||
// 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.
|
||||
// See also gc_enable() and gc_collect().
|
||||
// Note that gc_disable() is a NOP with `-gc none`.
|
||||
pub fn 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() {
|
||||
$if gcboehm_leak ? {
|
||||
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_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)
|
||||
|
||||
fn C.GC_get_warn_proc() 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 {
|
||||
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) {
|
||||
C.GC_set_warn_proc(cb)
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ pub fn gc_is_enabled() bool {
|
||||
// Note that gc_enable() is a NOP with `-gc none`.
|
||||
pub fn 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.
|
||||
// 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.
|
||||
// See also gc_enable() and gc_collect().
|
||||
// Note that gc_disable() is a NOP with `-gc none`.
|
||||
pub fn gc_disable() {}
|
||||
|
@ -9,23 +9,23 @@ pub struct VContext {
|
||||
|
||||
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 {
|
||||
buf1 := u64(ptr).hex()
|
||||
return buf1
|
||||
}
|
||||
|
||||
// str returns string equivalent of x
|
||||
// str returns the string equivalent of x.
|
||||
pub fn (x isize) str() string {
|
||||
return i64(x).str()
|
||||
}
|
||||
|
||||
// str returns string equivalent of x
|
||||
// str returns the string equivalent of x.
|
||||
pub fn (x usize) str() string {
|
||||
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 {
|
||||
return u64(cptr).hex()
|
||||
}
|
||||
@ -63,10 +63,10 @@ pub const max_u32 = u32(4294967295)
|
||||
pub const min_u64 = u64(0)
|
||||
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.
|
||||
@[direct_array_access; inline]
|
||||
fn (nn int) str_l(max int) string {
|
||||
// This implementation is the quickest with gcc -O2
|
||||
unsafe {
|
||||
mut n := i64(nn)
|
||||
mut d := 0
|
||||
@ -554,10 +554,9 @@ pub fn (b []u8) bytestr() string {
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
// byterune attempts to decode a sequence of bytes, from utf8 to utf32.
|
||||
// It return the result as a rune.
|
||||
// It will produce an error, if there are more than four bytes in the array.
|
||||
pub fn (b []u8) byterune() !rune {
|
||||
r := b.utf8_to_utf32()!
|
||||
return rune(r)
|
||||
|
@ -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
|
||||
// than len nothing will be changed.
|
||||
// trim trims the array length to "index" without modifying the allocated data. If "index" is greater than len nothing will be changed.
|
||||
pub fn (mut a array) trim(index int) {
|
||||
if index < a.len {
|
||||
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) {
|
||||
#a.val.arr.make_copy()
|
||||
#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
|
||||
}
|
||||
|
||||
// reduce executes a given reducer function on each element of the array,
|
||||
// resulting in a single output value.
|
||||
// reduce executes a given reducer function on each element of the array, resulting in a single output value.
|
||||
pub fn (a array) reduce(iter fn (int, int) int, accum_start int) int {
|
||||
mut accum_ := accum_start
|
||||
/*#for (let i = 0;i < a.arr.length;i++) {
|
||||
|
@ -22,13 +22,13 @@ pub fn panic_n(s string, n i64) {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
// IError holds information about an error instance
|
||||
// IError holds information about an error instance.
|
||||
pub interface IError {
|
||||
msg() string
|
||||
code() int
|
||||
}
|
||||
|
||||
// str returns the message of IError
|
||||
// str returns the message of IError.
|
||||
pub fn (err IError) str() string {
|
||||
return match err {
|
||||
None__ {
|
||||
@ -49,34 +49,34 @@ pub fn (err IError) str() string {
|
||||
// Error is the empty default implementation of `IError`.
|
||||
pub struct Error {}
|
||||
|
||||
// msg returns the message of Error
|
||||
// msg returns the message of Error.
|
||||
pub fn (err Error) msg() string {
|
||||
return ''
|
||||
}
|
||||
|
||||
// code returns the code of Error
|
||||
// code returns the code of Error.
|
||||
pub fn (err Error) code() int {
|
||||
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 {
|
||||
pub:
|
||||
msg string
|
||||
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 {
|
||||
return err.msg
|
||||
}
|
||||
|
||||
// msg returns the message of the MessageError
|
||||
// msg returns the message of the MessageError.
|
||||
pub fn (err MessageError) msg() string {
|
||||
return err.msg
|
||||
}
|
||||
|
||||
// code returns the code of MessageError
|
||||
// code returns the code of MessageError.
|
||||
pub fn (err MessageError) code() int {
|
||||
return err.code
|
||||
}
|
||||
@ -96,7 +96,7 @@ pub struct Option {
|
||||
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 {
|
||||
if o.state == 0 {
|
||||
return 'Option{ ok }'
|
||||
@ -112,7 +112,7 @@ pub struct _option {
|
||||
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 {
|
||||
if o.state == 0 {
|
||||
return 'Option{ ok }'
|
||||
@ -123,7 +123,7 @@ pub fn (o _option) str() string {
|
||||
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) {
|
||||
eprintln('> ${@FN} | ${x}')
|
||||
}
|
||||
|
@ -176,8 +176,7 @@ pub fn (x u8) hex() string {
|
||||
return res
|
||||
}
|
||||
|
||||
// hex returns a string with the hexadecimal representation
|
||||
// of the byte elements of the array.
|
||||
// hex returns a string with the hexadecimal representation of the byte elements of the array.
|
||||
pub fn (b []u8) hex() string {
|
||||
mut hex := ''
|
||||
for i in b {
|
||||
|
@ -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.race(JS.Array) JS.Promise
|
||||
|
||||
// The Promise object represents the eventual completion (or failure)
|
||||
// of an asynchronous operation and its resulting value.
|
||||
// Promise represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
|
||||
pub struct Promise[T] {
|
||||
mut:
|
||||
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)
|
||||
}
|
||||
|
||||
// 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] {
|
||||
promise := p.promise.catch(callback)
|
||||
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}
|
||||
}
|
||||
|
||||
// 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] {
|
||||
promise := JS.Promise.reject(error)
|
||||
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] {
|
||||
promise := JS.Promise.resolve(result)
|
||||
return Promise[T]{promise}
|
||||
}
|
||||
|
||||
// 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.
|
||||
// promise_race returns a promise, that fulfills or rejects, as soon as one of the promises in an iterable fulfills or rejects.
|
||||
// It returns the value or reason from that first promise.
|
||||
pub fn promise_race[T](promises []Promise[T]) Promise[T] {
|
||||
promises_ := JS.Array.prototype.constructor()
|
||||
|
||||
@ -70,8 +69,7 @@ pub fn JS.Promise.allSettled(JS.Array) JS.Promise
|
||||
/*
|
||||
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
|
||||
// the results of the input promises
|
||||
// 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.
|
||||
pub fn all(array []JS.Promise) Promise<JS.Array, js.promise.JsAny> {
|
||||
mut promise := JS.Promise(JS.Any(voidptr(0)))
|
||||
#promise = Promise.all(array.arr.arr);
|
||||
|
@ -480,7 +480,7 @@ pub fn (mut s []string) sort_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 {
|
||||
return s.clone()
|
||||
}
|
||||
|
@ -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
|
||||
// to their hash value into the newly sized key-value container.
|
||||
// Rehashes are performed when the load_factor is going to surpass
|
||||
@ -467,7 +467,7 @@ fn (mut m map) rehash() {
|
||||
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) {
|
||||
unsafe {
|
||||
// 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`.
|
||||
fn (mut m map) cached_rehash(old_cap u32) {
|
||||
old_metas := m.metas
|
||||
@ -509,7 +509,7 @@ fn (mut m map) cached_rehash(old_cap u32) {
|
||||
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.
|
||||
// If the key exists, its respective value is returned.
|
||||
fn (mut m map) get_and_set(key voidptr, zero voidptr) voidptr {
|
||||
|
@ -3,7 +3,7 @@
|
||||
// that can be found in the LICENSE file.
|
||||
module builtin
|
||||
|
||||
// IError holds information about an error instance
|
||||
// IError holds information about an error instance.
|
||||
pub interface IError {
|
||||
msg() string
|
||||
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 {
|
||||
return match err {
|
||||
None__ {
|
||||
@ -55,14 +55,14 @@ pub fn (err Error) code() int {
|
||||
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 {
|
||||
pub:
|
||||
msg string
|
||||
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 {
|
||||
if err.code > 0 {
|
||||
return '${err.msg}; code: ${err.code}'
|
||||
@ -70,12 +70,12 @@ pub fn (err MessageError) str() string {
|
||||
return err.msg
|
||||
}
|
||||
|
||||
// msg returns only the message of MessageError
|
||||
// msg returns only the message of MessageError.
|
||||
pub fn (err MessageError) msg() string {
|
||||
return err.msg
|
||||
}
|
||||
|
||||
// code returns only the code of MessageError
|
||||
// code returns only the code of MessageError.
|
||||
pub fn (err MessageError) code() int {
|
||||
return err.code
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import strings
|
||||
// updated. if you uncomment it you will see the issue
|
||||
// type rune = int
|
||||
|
||||
// str converts a rune to string
|
||||
// str converts a rune to string.
|
||||
pub fn (c rune) str() string {
|
||||
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]
|
||||
pub fn (ra []rune) string() string {
|
||||
mut sb := strings.new_builder(ra.len)
|
||||
@ -53,7 +53,7 @@ pub fn (c rune) repeat(count int) string {
|
||||
return res.repeat(count)
|
||||
}
|
||||
|
||||
// bytes converts a rune to an array of bytes
|
||||
// bytes converts a rune to an array of bytes.
|
||||
@[manualfree]
|
||||
pub fn (c rune) bytes() []u8 {
|
||||
mut res := []u8{cap: 5}
|
||||
|
@ -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'
|
||||
@[inline]
|
||||
pub fn (s string) normalize_tabs(tab_len int) string {
|
||||
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!'
|
||||
pub fn (s string) expand_tabs(tab_len int) string {
|
||||
if tab_len <= 0 {
|
||||
@ -2503,7 +2503,7 @@ pub fn (s string) repeat(count int) string {
|
||||
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 ' sss ssss'.fields() == ['sss', 'ssss']
|
||||
pub fn (s string) fields() []string {
|
||||
@ -2954,7 +2954,7 @@ pub:
|
||||
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.
|
||||
// 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 {
|
||||
@ -2983,7 +2983,7 @@ pub fn (s string) wrap(config WrapConfig) string {
|
||||
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 {
|
||||
if s == '' {
|
||||
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 {
|
||||
for ri.i >= ri.s.len {
|
||||
return none
|
||||
|
@ -92,8 +92,7 @@ pub fn string_from_wide2(_wstr &u16, len int) string {
|
||||
}
|
||||
}
|
||||
|
||||
// wide_to_ansi create an ANSI string, given a windows
|
||||
// style string, encoded in UTF-16.
|
||||
// wide_to_ansi create an ANSI string, given a windows style string, encoded in UTF-16.
|
||||
// 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.
|
||||
pub fn wide_to_ansi(_wstr &u16) []u8 {
|
||||
|
@ -3,7 +3,7 @@
|
||||
// that can be found in the LICENSE file.
|
||||
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 {
|
||||
return ((0xe5000000 >> ((b >> 3) & 0x1e)) & 3) + 1
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user