Re: Help!!
- Posted by Chris Bensler <bensler at nt.net> Sep 30, 2006
- 537 views
Chris Bensler wrote: > > Pete Lomax wrote: > > > > On Sat, 30 Sep 2006 12:29:25 -0700, Alex Chamberlain > > <guest at RapidEuphoria.com> wrote: > > > > >Can any one spot the mistake? > > Nope. I would have integer d, d=dat[i] for performance, and negate > > that test, for style, so it reads: > > if (d>='A' and d<='Z') or (d>='a' and d<='z').. > > ret&=d > > else > > res&='%'... > > but otherwise it looks fine and runs ok here. > > >It keeps generating machine exceptions. > > What version of Eu are you running on? > > Does trace(3) indicate the error line any better? > > For a long shot, try changing ret&= to ret=ret&, see if it makes any > > difference. > > > > Regards, > > Pete > > > > > A table would be better to test for valid chars.. > > }}} <eucode> > sequence VALID_CHARS > VALID_CHARS = repeat(0,255) -- NULL char is not supported > VALID_CHARS['0'..'9'] = 1 > VALID_CHARS['A'..'Z'] = 1 > VALID_CHARS['a'..'z'] = 1 > for i = 1 to length(VALID_CHARS) do > if VALID_CHARS[i] then > VALID_CHARS[i] = i > else > VALID_CHARS[i] = sprintf("%%%02x",{i}) > end if > end for > > global function url_encode(sequence dat) > sequence ret > > ret = {} > > for i = 1 to length(dat) do > ret &= VALID_CHARS[dat[i]] > end for > > return ret > end function > </eucode> {{{ > > > Machine exceptions will popup in places entirely unrelated to the error. > Without the rest of the code, it would be hard to determine what the problem > is. Test the function in a minimal demo application. > > BTW, what is convertDecimal() for exactly? > Converts the char code to urlencoded hex? > I replaced it with sprintf() which will convert char codes to the correct url > encoded hex. > > > Chris Bensler > ~ The difference between ordinary and extraordinary is that little extra ~ I just thought of another improvement. If you were using a table anyways, you could pre-fill the table with the correct chars/urlcodes, so you simply have to append the data stored in the table for the desired char. ( I modified the quoted snippet above ) Chris Bensler ~ The difference between ordinary and extraordinary is that little extra ~