Write an equivalent function which can URL-encode a string in-place, i.e. assuming the buffer is large enough (thrice the length of the original string), a call such as URLencode(str) will write the URL-encoded version in the same buffer, possibly lengthened to up to thrice its original length.
Your function cannot use any additional storage space that grows proportionally with the length of the string. The smallest, fastest, and most efficient implementations win.
Hold up, heyyyyyyyy
for my cudderz who be thinkin c' soft
We don't, caaaare
We gon' code it til the wheels fall off
Hold up, heyyyyyyyy
for my cudderz who be actin too bold
Take a, seeaaaaaat
Hope you ready for the next episode
HeyyyeyyyeEYEYyyyEYYYY....
.... code c everday!
urlEncode (h:t) =
let str = if reserved (ord h) then escape h else [h]
in str ++ urlEncode t
where
reserved x
| x >= ord 'a' && x <= ord 'z' = False
| x >= ord 'A' && x <= ord 'Z' = False
| x >= ord '0' && x <= ord '9' = False
| x <= 0x20 || x >= 0x7F = True
| otherwise = x `elem` map ord [';','/','?',':','@','&'
,'=','+',',','$','{','}'
,'|','\\','^','[',']','`'
,'<','>','#','%','"']
-- wouldn't it be nice if the compiler
-- optimised the above for us?
encodeURL = concatMap encodeChar
where
encodeChar c | elem c "-_.~" || any (flip inRange c) (zip "aA0" "zZ9") = c:""
| otherwise = '%': showHex (ord c) ""
>>18
Let's say you have to take an exam. Your task is: "Create a class that acts as an dynamic array, similar to the vector of the STL".
As the FrozenVoid you are, you would just ignore the task and use #include <vector>. Failure to accomplish the task, meaning you won't pass your exam. Well done, smartass.
>>21
I can't help it. I have to find out if he is just trolling or if he really is that stupid.
Name:
Anonymous2009-01-17 10:36
Disregard my previous post >>24, I just figured out how to do it correctly.
>>25 I can't help it. I have to find out if he is just trolling or if he really is that stupid.
You're gonna get trolled either way [spoier]and fuck up /prog/ in the process[spoiler].
>>30
Let's say you're still missing the point of the entire thread and any post in it. You just can't admit, that your silly javascript-function is totally misplaced here and now you're trying to avoid topic by distracting from that original post. But your puny little attempts won't work here.
Unless you're really convinced you did something right there. But nobody can be that stupid.
>>31
Lets say encodeURI function is way more efficient then any custom alternative you can write in JavaScript.
bench(loop,encodeURI,1000000,'test^test')=2074ms
Note that you can't get better then 1500ms for this loop,even with single-pass replace without regexp.
_________________________
orbis terrarum delenda est
>>31
Seriously, you're not going to accoplish anything here. FrozenVoid will never admit to: a) bein stupid; b) being a troll. And you'll still end up fucking up /prog/.
>>33
I give up. But nobody can be that stupid.
And I take that back. Appearantly there is somebody who actually can be that stupid. Where was this GM-Script again?