Module strutil

Module strutil 

Source

Structs§

StrWithPos
A string with a cursor position (rune-based, not byte-based).

Constants§

NO_STR_POS
Sentinel value for StrWithPos.pos to indicate no position.

Functions§

add_elem_uniq
Add an element to a vec if it’s not already present.
atoi_no_err
Parse an integer from a string, returning 0 on error.
atomic_rename_copy
Atomically copy a file by writing to a temp file then renaming. On Unix, sets file permissions to perms. On Windows, permissions are ignored.
combine_str_arrays
Combine two string arrays, removing duplicates while preserving order.
ellipsis_str
Truncate a string with “…” if it exceeds maxLen (char-safe).
filter_valid_arch
Convert known architecture names to standard patterns.
get_first_line
Get the first line of a string.
get_line_col_from_offset
Get line and column from a byte offset in content.
getrandom 🔒
Platform-independent random bytes. Uses /dev/urandom on Unix, hash-based randomness on Windows.
has_binary_data
Check if data contains binary (non-text) bytes. Returns true if any byte < 32 other than \n, \r, \t, \f, \b.
indent_string
Indent each non-empty line of a string.
is_binary_content
Check if content is binary by examining up to 8192 bytes. Checks for null byte ratio > 1% and UTF-8 validity.
longest_prefix
Find the longest common prefix of a set of strings, bounded by a root.
move_to_front
Move element at idx to the front of the slice. Returns a new vec.
random_hex_string
Generate a random hex string of the given number of hex digits.
remove_elem
Remove an element from a vec. Returns a new vec without the element.
shell_hex_escape
Shell hex escape a string (each byte as \xNN).
slice_idx
Find the index of an element in a slice. Returns -1 if not found.
star_match_string
Match a delimited string with a pattern string. * matches a single part, ** matches the rest of the string (only valid at end).
truncate_string
Truncate a string with “…” if it exceeds maxLen (char-safe).
write_file_if_different
Write file only if contents differ. Returns true if file was written.