Package str_utils_pkg
Functions
- bytes_to_str(byte bytes)
- Parameters:
bytes (byte)
- str_ends_with(string s, string sub)
Returns 1 when string 's' ends with substring 'sub'.
- Parameters:
s (string)
sub (string)
- str_find(string s, string sub, int range_lo = 0, int range_hi = -1)
Returns the index of first occurrence of string 'sub' within string 's''s given index range. Returns -1 otherwise.
- Parameters:
s (string)
sub (string)
range_lo (int)
range_hi (int)
- str_has_substr(string s, string sub, int range_lo = 0, int range_hi = -1)
Returns 1 if string 's' has substring 'sub' within the given index range. 0 Otherwise.
- Parameters:
s (string)
sub (string)
range_lo (int)
range_hi (int)
- str_join(string s, string delim = " ")
Returns a string concatenated from the provided queue of strings 's'.
The concatenation is performed using the 'delim' arg as the delimiter.
- Parameters:
s (string)
delim (string)
- str_path_basename(string filename, bit drop_extn = 1'b0)
Returns the basename of the file.
Optionally, it takes a bit flag to drop the extension from the basename if desired. Examples: path/to/foo.bar => (foo.bar, foo) path/to/foo/bar => (bar, bar) path/to/foo/bar/ => (bar, bar) path/to/foo/bar/. => (., .) / => (/, /)
- Parameters:
filename (string)
drop_extn (bit)
- str_path_dirname(string filename)
Returns the dirname of the file.
Examples
- Parameters:
filename (string)
- str_remove_sections(string s, string start_delim, string end_delim, bit remove_start_delim = 1, bit remove_end_delim = 1)
Cuts sections (such as comments) from string s starting and ending with provided substrings.
start_delim
substring representing the start of section to be removed (e.g. "//", "/*").
end_delim: substring representing the end of the section to be removed (e.g. "\n", "*/"). remove_start_delim: include the start_delim substring in the removal. remove_end_delim: include the end_delim substring in the removal.
- Parameters:
s (string)
start_delim (string)
end_delim (string)
remove_start_delim (bit)
remove_end_delim (bit)
- str_replace(string s, string sub, string new_sub)
Find the first match string 'sub' in 's' and replace it with 'new_sub'. TODO: Add support for global replacement.
- Parameters:
s (string)
sub (string)
new_sub (string)
- str_rfind(string s, string sub, int range_lo = 0, int range_hi = -1)
Returns the index of last occurrence of string 'sub' within string 's''s given index range. Returns -1 otherwise.
- Parameters:
s (string)
sub (string)
range_lo (int)
range_hi (int)
- str_split(string s, string result, byte delim = " ", bit strip_whitespaces = 1'b1)
Splits the input
string
on the given single-character delimiterdelim
.The split tokens are pushed into the
result
queue. The whitespaces on each split token are stripped by default, which can be turned off. TODO: allow arbitrary length delimiter.- Parameters:
s (string)
result (string)
delim (byte)
strip_whitespaces (bit)
- str_starts_with(string s, string sub)
Returns 1 when string 's' starts with substring 'sub'.
- Parameters:
s (string)
sub (string)
- str_strip(string s, string chars = " \t\n", bit lstrip = 1'b1, bit rstrip = 1'b1)
Strips a given set of characters in string 's'.
The set of characters to strip is provided as a string. If not set, all whitespace characters are stripped by default. Stripping is done at both ends, unless the user turns off the stripping from one of the ends.
- Parameters:
s (string)
chars (string)
lstrip (bit)
rstrip (bit)
- str_to_bytes(string s, byte bytes)
Converts a string to an array of bytes.
- Parameters:
s (string)
bytes (byte)
Converts an array of bytes to a string.