SystemVerilog Parse Function
This function will parse through a string in
, and separate out terms separated by separated
, returning the resulting terms in the out
array.
function automatic void parse (
output string out [],
input string in,
input byte separator = "|"
);
automatic int index [$];
foreach (in[i]) begin
if (in[i] == separator) begin
index.push_back(i-1);
index.push_back(i+1);
end
end
index.push_front(0);
index.push_back(in.len()-1);
out = new[index.size()/2];
foreach (out[i]) begin
out[i] = in.substr(index[2*i], index[2*i+1]);
end
endfunction