Re: Help!!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Alex Chamberlain wrote:
> 
> Thanks for all your help - it was actually how i was using curl that was
> causing
> the problem, but i've changed the function anyway. I need to test them all for
> speed as my program has to upload ~23000 products!!

This might be a bit faster as it avoid appending and precomputes as much as it
can ...

-- Initialize list of valid characters
sequence vValidChars
vValidChars = repeat(0, 256)
vValidChars['A'+1..'Z'+1] = repeat(1, 26)
vValidChars['a'+1..'z'+1] = repeat(1, 26)
vValidChars['0'+1..'9'+1] = repeat(1, 10)

-- Initialize list of converted characters
sequence vConverted
vConverted = repeat({0,0,0} , 256)
for i = 0 to 255 do
    vConverted[i+1] =  '%' & convertDecimal(i, 16)
end for

global function url_encode(sequence dat)
 sequence ret
 integer lNextChar
 integer lPos, lEnd

 -- Create a string big enough to hold largest possible conversion
 ret = repeat(0, length(dat) * 3)

 -- copy original to result
 ret[1..length(dat)] = dat

 -- Set up position to examine and current end position
 lPos = 1
 lEnd = length(dat)

 -- Examine each char, skipping over good ones and
 -- copying in converted ones
 for i = 1 to length(dat) do
  lNextChar = ret[lPos]+1

  if vValidChars[lNextChar] = 0
  then
   -- shift remaining string right
   ret[lPos+3 .. lEnd+2] = ret[lPos+1 .. lEnd]
   -- copying in pre-converted string
   ret[lPos..lPos+2] = vConverted[lNextChar]
   -- adjust positions
   lPos += 2
   lEnd += 2
  end if

  -- skip over char just examined.
  lPos += 1
 end for

 -- return fully converted string.
 return ret[1..lPos-1]
end function




-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu