PDA

View Full Version : Maybe you can see something I am missing?



efilnikufecin
04-12-2007, 03:52 PM
I'm getting an error with the attached script:

> verify anvil

No closing " found (anvil.ash, line 104)

So maybe I forgot to close a string? Well I checked, and line 104 contains 1 hard coded string, a URL and it has it's closing ".

I also checked for a missing closing ) since there is so many, but they are all in place verified by context's built in control character matching.

Any help would be greatly appreciated.

holatuwol
04-12-2007, 06:16 PM
When inline comments were added, string parsing wasn't considered. So the "http://" is creating a comment line.

efilnikufecin
04-12-2007, 08:38 PM
Thanks Holatuwol!
I modified the script. Now I have come to realize that what I was telling the script to do in this function:


string remove_unsafe_chars(string source)
{
print("removing unsafe chars");
//maybe more chars need added, but this should be fine for now
string safechars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX YZ1234567890-+*/\().%<>";
string temp = source;
for count from length( temp ) downto 0
{
print(count);
if( !contains_text( safechars, substring( temp, count, count ) ) )
{
temp = substring( temp, 0, count ) + substring( temp, count + 1, length( temp ) );
}
}
return temp;
}

was to go through 253,934 characters 1 at a time to check them against the list of safe characters and if they are "not safe" remove them. That's a bit much. The goal is to remove all the tabs, and #13#10 control characters along with any other characters which I cannot test for and remove in a script. Any suggestions of how else to handle this? Modified version attached.

holatuwol
04-12-2007, 10:53 PM
You could use split_string, which takes a regular expression, and then concatenate the pieces together. Remember to use the negation of your safe character set.

Alternatively ... just generate a list of unsafe characters that you know you don't want to handle (there really aren't that many ... at least, not as many as you're imagining) and replace those.

efilnikufecin
04-12-2007, 11:50 PM
You could use split_string, which takes a regular expression, and then concatenate the pieces together. Remember to use the negation of your safe character set.

Alternatively ... just generate a list of unsafe characters that you know you don't want to handle (there really aren't that many ... at least, not as many as you're imagining) and replace those.


http://www.feesher.com/anvil/index.php

Tab, carriage return, and Line feed are the main "unsafe chars" The primary problem is with Tab which butts against every piece of data in the html source I am parsing. That rules out generating a list because kolmafia handles these characters in a script in a different way than would be desired in this situation.

As for split_string, I just don't understand regular expressions, and reading about them so far has increased my understanding of them to about 1%. I have not been able to find many any samples to look at which show the beginning string, and then the end results (with exception to brief one given with the introduction of split_string).