Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

[prog-challenge] In-Place URL Encoding

Name: Anonymous 2009-01-17 7:23

Using the encoding ranges specified in the following function

URLencode(char *out, char *in) {
 char a;
 while((a=*in)) {
  if((a>='A')&&(a<='Z')||(a>='a')&&(a<='z')||(a>='0')&&(a<='9')||(a=='-')||
     (a=='_')||(a=='.')||(a=='~')) {
   *(out++) = a;
  } else {
   sprintf(out,"%%%02x",a);
   out+=3;
  }
  in++;
 }
 *out=0;
}


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.

Name: Anonymous 2009-01-17 7:31

char a;
 while((a=*in)) {
  if((a>='A')&&(a<='Z')||(a>='a')&&(a<='z')||(a>='0')&&(a<='9')||(a=='-')||
     (a=='_')||(a=='.')||(a=='~')) {
   *(out++) = a;
  } else {
   sprintf(out,"%%%02x",a);
   out+=3;
  }
  in++;
 }
 *out=0;
}

Name: Anonymous 2009-01-17 7:32

URLencode(char *out, char *in) {
 char a;
 while((a=*in)) {
  if((a>='A')&&(a<='Z')||(a>='a')&&(a<='z')||(a>='0')&&(a<='9')||(a=='-')||
     (a=='_')||(a=='.')||(a=='~')) {
   *(out++) = a;
  } else {
   sprintf(out,"%%%02x",a);
   out+=3;
  }
  in++;
 }
 *out=0;
}

Name: Anonymous 2009-01-17 7:32

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!

Name: Anonymous 2009-01-17 7:32

great shit man, NO EXCEPTION

Name: Anonymous 2009-01-17 7:34

[i]BB CODING[i] "F" 'r' o M my bed

Name: Anonymous 2009-01-17 7:35

This is how japanese programmers code.

URLencode(char *out, char *in) {
 char a;
 while((a=*in)) {
  if((a>='A')&&(a<='Z')||(a>='a')&&(a<='z')||(a>='0')&&(a<='9')||(a=='-')||
     (a=='_')||(a=='.')||(a=='~')) {
   *(out++) = a;
  } else {
   sprintf(out,"%%%02x",a);
   out+=3;
  }
  in++;
 }
 *out=0;
}

Name: Anonymous 2009-01-17 7:38

EVERY HEARD OF CTYPE

Name: Anonymous 2009-01-17 7:42

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?

        escape x = '%':showHex (ord x) ""

urlEncode [] = []

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-17 7:45

encodeURI(url)

_________________________
orbis terrarum delenda est

Name: Anonymous 2009-01-17 8:02

def URLencode(url):
     def escape(a):
         if a.isalnum() or a in '-_.~':
             return a
         else:
             return '%' + hex(ord(a))[2:]
     return ''.join(map(escape, url))

Name: Anonymous 2009-01-17 8:07

/prog/ does not do your homework for you.

Name: Anonymous 2009-01-17 8:30

>>12
Not homework. It's a puzzle I've been thinking about, and there are others too if you want to try them.

Name: Anonymous 2009-01-17 9:03

>>13
I dont think your ready for writing puzzles yet, judging by your code

Name: Anonymous 2009-01-17 9:20

>>9
import Ix
import Char
import Numeric

encodeURL = concatMap encodeChar
   where
   encodeChar c | elem c "-_.~" || any (flip inRange c) (zip "aA0" "zZ9") = c:""
                | otherwise = '%': showHex (ord c) ""


Still not what OP asked for, though.

Name: Anonymous 2009-01-17 9:34

>>10
>>1
Write an equivalent function which can URL-encode a string in-place
You didn't notice the difference between write and call, did you?
IHBT

Name: Anonymous 2009-01-17 9:56

>>16
Why did you link to an invisible post?

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-17 10:08

>>16
Would you write your version of Math.pow(num,power) or use the built-in inline? Which one is more efficient?


_________________________
orbis terrarum delenda est

Name: Anonymous 2009-01-17 10:10

its possible the easier solution is to just encode everything, else you'll have to do a bunch of memmoves

Name: Anonymous 2009-01-17 10:16

>>18
GTFO, please.

Name: Anonymous 2009-01-17 10:17

>>16
See what happens when you fail to ignore a troll post? Tsk... I hope you at least know better now.

Name: Anonymous 2009-01-17 10:19

>>20
☃ Please ignore troll posts! ☃

http://userscripts.org/scripts/review/40415

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-17 10:25

>>20
İronic,using profanity and politeness in the same sentence.

_________________________
orbis terrarum delenda est

Name: Anonymous 2009-01-17 10:30

This is very easy but the solution is actually slower. So it's not a good idea to do it.

Name: Anonymous 2009-01-17 10:35

>>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: Anonymous 2009-01-17 10:36

Disregard my previous post >>24, I just figured out how to do it correctly.

Name: Anonymous 2009-01-17 10:45

>>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].

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-17 10:57

>>25 "Let's say you have to take an exam"
Let's say i don't have to take an exam,instead i'm helping a newbie to convert urls into proper format.

_________________________
orbis terrarum delenda est

Name: Anonymous 2009-01-17 11:12

>>28
Let's say you didn't read >>1 or in fact the entire thread at all.
Also 0/10.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-17 11:20

>>29
Lets say i did read >>1 but >>28 refers to >>25

_________________________
orbis terrarum delenda est

Name: Anonymous 2009-01-17 11:26

>>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.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-17 11:33

>>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

Name: Anonymous 2009-01-17 11:36

>>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/.

Name: Anonymous 2009-01-17 11:38

*accomplish

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-17 11:41

http://frozenvoid.blogspot.com/2008/12/benchmark-function.html
http://frozenvoid.blogspot.com/2008/12/loop-functions.html
^for reference on how i benchmark functions.
_________________________
orbis terrarum delenda est

Name: Anonymous 2009-01-17 11:44

>>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?

Name: Anonymous 2009-01-17 14:10

>>36
☣ Please try to ignore troll posts! ☣

http://userscripts.org/scripts/show/40415

Name: Anonymous 2010-11-27 2:51

<

Name: Anonymous 2010-12-17 1:24

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2011-02-03 7:16

Don't change these.
Name: Email:
Entire Thread Thread List