gvpr "split", "tokens", and "index" functions produce incorrect results
Steps to reproduce
(on Linux)
echo | gvpr -f gvprStringBugs.gvpr
gvprStringBugs.gvpr:
BEGIN{
int i, j, l, cnt;
string POS, st, tst, tok[int];
void tstStuff(string inStr){
print ("// tok array count: ",cnt);
for (i=0;i<cnt;i++){
print("// tok[",i,"] >>",tok[i],"<< should NOT include trailing spaces or junk chars");
st=tok[i];
//st=sub(tok[i],"[ ]"); // remove tabs and spaces !!
l=length(st);
print("// length (st) : ",l);
j=index(st," ");
print("// index of space (st) : ", j, " << must NOT be less than -1");
st=sub(st,"[ ]");
print ("// st >>",st,"<<");
l=length(st);
print("// length (st) : ",l);
print("//");
}
}
tst=" abc def ghijk 3456789 012 ";
print("\n*****", tst, "******");
print("********* space delimiter *****************");
print("********* split results *****************");
cnt=split(tst, tok );
tstStuff();
print("\n********* tokens results ***************");
cnt=tokens(tst, tok );
tstStuff();
tst="^abc^def^^^ghijk^3456789^012^^^";
print("\n*****", tst, "******");
print("********* ^ delimiter *****************");
print("********* split results *****************");
cnt=split(tst, tok,"^" );
tstStuff();
print("\n********* tokens results ***************");
cnt=tokens(tst, tok, "^" );
tstStuff();
}
Expected Behaviour
- split & tokens commands should "tokenize" as documented (tokenize based on delimiters)
- index should return index of search string in target string
Actual Behaviour
- split & tokens commands seem to "tokenize" as expected, but then leave delimiter and sometimes junk chars on the end of the tokens
- index command returns the negative of correct index if search string was found
Two examples of wrong results:
(tok[3] should be 3456789)
// tok[3] >>3456789 << should NOT include trailing spaces or junk chars
// length (st) : 8
// index of space (st) : -7 << must NOT be less than -1
// st >>3456789<<
// length (st) : 7
and (tok[7] should be 012)
// tok[7] >>012^yU<< should NOT include trailing spaces or junk chars
// length (st) : 6
// index of space (st) : -1 << must NOT be less than -1
// st >>012^yU<<
// length (st) : 6
OS Version
Linux highway 5.4.0-70-generic #78 (closed)-Ubuntu SMP Fri Mar 19 13:29:52 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Graphviz Version
gvpr version 2.47.1 (20210417.1919) - works OK
gvpr version 2.47.2 (20210527.0053) - fails
Additional info
split & tokens are particularly useful in parsing edge pos values.
Edited by steve roush