Bug - Not A Bug r14844 - Trouble with quotation marks

Fluxxdog

Active member
Sample code:
Code:
int[item]listing;
listing[$item["meat" stick]]=20;
listing[$item[martini]]=20;
string test_prop;
foreach i,n in listing{
	if(test_prop!="") test_prop+=";";
	test_prop+=n+":"+i;
}
set_property("_testing",test_prop);

foreach x,y in split_string(get_property("_testing"),";"){
	print(y);
}
Output:
Code:
20:"
meat"
stick
20:martini
Output is expected to be:
Code:
20:"meat" stick
20:martini
For reference, from the _pref.txt file:
Code:
_testing=20\:"meat" stick;20\:martini
 
Yeah. Using ";" to separate multiple items which might contain HTML character entities doesn't work well, does it? Having looked at your program, the Output is exactly what I expect it to be. Since you expect something different, I suggest that you change your expectations. And, more to the point, given that this is how string manipulation works, I'd suggest you use "|" or some other character which does not actually appear in the items that you are concatenating into the setting.

This is a bug in your ASH program - not in KoLmafia.
 
This:
Code:
int[item]listing;
listing[$item["meat" stick]]=20;
listing[$item[martini]]=20;
string test_prop;
foreach i,n in listing{
	if(test_prop!="") test_prop+="|";
	test_prop+=n+":"+i;
}
set_property("_testing",test_prop);

foreach x,y in split_string(get_property("_testing"),"|"){
	print(y);
}
...gives this:
Code:
_testing=20\:"meat" stick|20\:martini
Code:
2
0
:
&
q
u
o
t
;
m
e
a
t
&
q
u
o
t
;

s
t
i
c
k
|
2
0
:
m
a
r
t
i
n
i
Did I do something else wrong?
 
No, I gave incomplete advice. Sorry!

split_spring() takes a regular expression. "|" is a character in regular expressions, used as an OR. So, ":|;" matches ":" OR ";".

You need to escape the special character. I'd expect "\\|" to work the way you want.
 
Just having a crackerjack day ^^ I forgot that myself. Seems \\| doesn't work well as that gives:
Code:
20:"meat" stick\
20:martini
I can just see that extra backslash causing trouble. Gonna use @ for this. Thanks Veracity!
 
I meant how it's stored. I use a variable for the delimiter in my scripts so it's consistent on all my method calls. If I used |, I'd need \| for storing the property and \\| for the split string.
 
Back
Top