Utils
#load "std/utils.bl"
Set of various utility functions.
set_flag
set_flag :: fn (flags: *?T, flag: T) T #inline
Set flag
in flags
input. This function is valid for numeric and enum types (checked by assert).
File: utils.bl
set_flags
set_flags :: fn (flags: *?T, flags_to_be_set: ...T) T #inline
Set all flags_to_be_set
in flags
.
File: utils.bl
clr_flag
clr_flag :: fn (flags: *?T, flag: T) T #inline
Clear flag
in flags
input. This function is valid for numeric and enum types (checked by assert).
File: utils.bl
clr_flags
clr_flags :: fn (flags: *?T, flags_to_be_cleared: ...T) T #inline
Clear all flags_to_be_cleared
in flags
.
File: utils.bl
is_flag
is_flag :: fn (flags: ?T, flag: T) bool #inline
Check whether flag
is set in flags
. This function is valid for numeric and enum types
(checked by assert).
File: utils.bl
is_all_flags
is_all_flags :: fn (flags: ?T, flags_to_check: ...T) bool #inline
Check whether all flags_to_check
are set in flags
.
File: utils.bl
is_one_or_more_flags
is_one_or_more_flags :: fn (flags: ?T, flags_to_check: ...T) bool #inline
Check whether at least one of flags_to_check
is set in flags
.
File: utils.bl
make_flags
make_flags :: fn (f1: ?T, other: ...T) T
Create new flags from combination of other
flags.
File: utils.bl
env_get
env_get :: fn (var: string_view) string
Reads environment variable specified by var
name. Result is empty in case no such variable was
found or has no content. It's caller responsibility to delete result string.
File: utils.bl
env_set
env_set :: fn (var: string_view, value: string_view) #inline
Sets environment variable.
File: utils.bl
random_seed_time
random_seed_time :: fn () #inline
Sets seed for std.rand
or utility function random_number based on current
system tick time.
File: utils.bl
random_number
random_number :: fn (min :: 0, max :: 1) s32 #inline
Generates random number in specified range random_seed_time
or by std.srand
call.
File: utils.bl
sort
sort :: fn (list: []?T, cmp: *fn (a: *T, b: *T) bool)
Slice sorting utility.
File: utils.bl
find_if
find_if :: fn (arr: []?T, func: *fn (: *T) bool) (value: *T, index: s64) #inline
Iterate over arr
slice and return pointer to the value and it's index if func
validator
function returs true.
The func
is called for every element in the arr
slice and pointer to the current element
is passed into this function.
In case no element was found, function returns null pointer and -1 index.
File: utils.bl
hash_combine
hash_combine :: fn (first: ?T, second: T, more: ...T) T #inline
Combine two or more hashes into one, T is expected to be an integer type (checked by static assert).
File: utils.bl
is_power_of_two
is_power_of_two :: fn (n: usize) bool #inline
Check whether the number n
is power of 2.
File: utils.bl
next_pow_2
next_pow_2 :: fn (n: s64) s64 #inline
Finds next power of 2.
File: utils.bl
utf8_to_utf32
utf8_to_utf32 :: fn (utf8_str: string_view, out_utf32_str: *[..]u32) Error
Converts UTF8 encoded string to UTF32.
File: utils.bl
utf8_to_utf32_single_char
utf8_to_utf32_single_char :: fn (utf8: string_view) (utf32: u32, decoded_bytes: s32, state: Error) #inline
File: utils.bl
utf32_to_utf8
utf32_to_utf8 :: fn (utf32_str: []u32, out_utf8_str: *string) Error
Converts UTF32 encoded string to UTF8.
File: utils.bl
utf32_to_utf8_single_char
utf32_to_utf8_single_char :: fn (utf32_char: u32, out_utf8_str: *string) Error
Appends the out_utf8_str
string with utf8 characters converted from utf32_str
input.
File: utils.bl
reinterpret_read_any
reinterpret_read_any :: fn (T: type, value: Any) T #inline
File: utils.bl
reinterpret_write_any
reinterpret_write_any :: fn (dest: Any, value: ?T) usize #inline
File: utils.bl