From: superpollo on 22 Jan 2010 12:34 superpollo ha scritto: > Janis Papanagnou ha scritto: >> superpollo wrote: >>> Loki Harfagr ha scritto: >>>> Fri, 22 Jan 2010 16:12:50 +0100, superpollo did cat : >>>> >>>>> hi. >>>>> >>>>> is there a smarter way to do percent decoding (and encoding) other >>>>> than >>>>> a mere succession of sed substitutions? >>>>> >>>>> bye >>>> >>>> there is. >>> >>> will you kindly post it? >> >> You still don't get it? >> >> Good luck! > > ok so the thing is ... i only can ask questions if i already know the > answer :-) ? > > beautiful ok that's how i do it: if [ "$REQUEST_METHOD" == "GET" ] then DATA=$QUERY_STRING elif [ "$REQUEST_METHOD" == "POST" ] then DATA=$(head --bytes="$CONTENT_LENGTH") NAME=$(echo "$DATA" | sed -e "s/^\(.*\)=.*$/\1/g") ENCVALUE=$(echo "$DATA" | sed -e "s/^.*=\(.*\)$/\1/g") PRINTFVALUE=$(echo "$ENCVALUE" | sed -e "s/+/ /g" \ -e "s/%\([0-9A-F][0-9A-F]\)/\\\\x\1/g") VALUE=$(printf "$PRINTFVALUE") any suggestion for improvementt? bye
From: Seebs on 22 Jan 2010 12:47 On 2010-01-22, superpollo <utente(a)esempio.net> wrote: > sorry, but this time i do not think that applies to my post. it might > have been short, but it was clear enough. The original post wasn't, because that term is not all that widely used. More generally, you could have given a lot more information. What kinds of data sets do you need to work on? What have you tried already, and why doesn't it meet your needs? There are a lot of languages in which this is a one-liner, I'd guess. Basically, more data about what you need to do would be helpful. Do you have significant performance issues to worry about? Are you doing plain 8-bit strings, or UTF8, or UTF16, or... So, really, I don't think you gave us nearly enough information to allow us to give *good* answers. If I needed to do this, I'd probably just grab either a list of restricted characters, or a list of allowed characters, and do a short C program to do the conversion, then do $(url_encode "$foo") in sh. #include <stdio.h> #include <string.h> static char *allowed = "abcdef..."; int main(int argc, char **argv) { int i; char *s; for (i = 1; i < argc; ++i) { for (s = argv[i]; *s; ++s) { if (strchr(allowed, *s)) { putchar(*s); } else { printf("%%%02x", *s); } } putchar('\n'); } return 0; } Fill in "allowed" as you wish. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Seebs on 22 Jan 2010 12:47 On 2010-01-22, superpollo <utente(a)esempio.net> wrote: > ok so the thing is ... i only can ask questions if i already know the > answer :-) ? The point is that you haven't really given anyone enough information to let them determine what answers would be useful. Do you have performance requirements? -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: superpollo on 22 Jan 2010 13:03 Seebs ha scritto: > On 2010-01-22, superpollo <utente(a)esempio.net> wrote: >> ok so the thing is ... i only can ask questions if i already know the >> answer :-) ? > > The point is that you haven't really given anyone enough information > to let them determine what answers would be useful. > > Do you have performance requirements? not really... i just felt that "My" method was ugly :-( thanks
From: Stephane CHAZELAS on 22 Jan 2010 15:16 2010-01-22, 16:12(+01), superpollo: > is there a smarter way to do percent decoding (and encoding) other than > a mere succession of sed substitutions? $ perl -MURI::Escape -le 'print uri_escape "3% total"' 3%25%20total -- St�phane
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Want to obtain single line output based on a file. Next: Simple regex question |